OS-lab0


实验报告

lab0思考题

thinking0.1

不一样,在新建README.txt时候,处于Untracked状态,文件第二行显示"Untracked files"。当add 追踪再修改处于已修改状态,Modified.txt显示"Changes not staged for commit",此时使用add命令进入Stage区。这两次add的功能并不相同,第一次是追踪,第二次是提交修改。

thinking0.2

Add the file --> git add
Stage the file --> git add
commit --> git commit

thinking0.3

1.git checkout -- print.c
2.git reset HEAD print.c
3.git rm --cached print.c

thinking0.4

3 hashcode:d5b5d0e2008b045060fc390388ed88519e337857
2 hashcode:3afeaf4e09d5ebb5a811f24dfd9e8357b47d021b
1 hashcode:8e72b92edb7dd5370ab5ce48d270a9a32ebf78aa
git reset --hard HEAD^ 显示当前在版本2
git reset --hard 8e72b92edb7dd5370ab5ce48d270a9a32ebf78aa显示在版本1
git reset --hard d5b5d0e2008b045060fc390388ed88519e337857又返回到版本3

thinking0.5

echo first直接在shell输出first
echo second > output.txt 将second输出到output中,若文件已存在并替换原来的内容
echo third > output.txt 同理,output中只有third
echo forth >> output.txt 将forth写到output原有内容之后,此时文件中显示
third
forth

thinking0.6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
test
1 echo Shell Start
2 echo set a = 1
3 a=1
4 echo set b = 2
5 b=2
6 echo set c = a+b
7 c=$[$a+$b]
8 echo c = $c
9 echo save c to ./file1
10 echo $c>file1
11 echo save b to ./file2
12 echo $b>file2
13 echo save a to ./file3
14 echo $a>file3
15 echo save file1 file2 file3 to file4
16 cat file1>file4
17 cat file2>>file4
18 cat file3>>file4
19 echo save file4 to ./result
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
command
1 echo echo Shell Start > test
2 echo echo set a = 1 >> test
3 echo a=1 >> test
4 echo echo set b = 2 >> test
5 echo b=2 >> test
6 echo echo set c = a+b >>test
7 echo c='$[$a+$b]' >> test
8 echo echo c = '$c' >> test
9 echo echo save c to ./file1 >> test
10 echo echo '$c>'file1 >>test
11 echo echo save b to ./file2 >> test
12 echo echo '$b>'file2 >>test
13 echo echo save a to ./file3 >> test
14 echo echo '$a>'file3 >>test
15 echo echo save file1 file2 file3 to file4 >> test
16 echo cat file1'>'file4 >> test
17 echo cat file2'>>'file4 >> test
18 echo cat file3'>>'file4 >>test
19 echo echo save file4 to ./result >>test

难点分析

Exercise0.1

sed -n(安静模式)即只输出经过sed修改后的内容

Exercise0.2

在bash可执行文件中,熟悉文法结构,每一条都是命令,所以if while中的参数也是命令,-ne,-eq等命令,且须注意在关系成立时返回0,与常规语言不同。

Exercise0.3

使用grep和awk指令结合使用,可以使用创建中间文件然后再删除,也可以使用管道重定向即一行写完:grep -n $2 $1 | awk -F: '{print $1}' > $3

Exercise0.4

2.1存在一个调用子目录的Makefile:cd  childDir && $(MAKE)
2.2链接操作:gcc code/fibo.o code/main.o -o fibo
2.3头文件不在当前目录gcc -c fibo.c -o fibo.o -I ../include 使用-I参数(预处理过程中需要替换#include中文件头)所以在汇编的第一步预处理过程中也是需要fibo.h头文件

实验体会

实验的基本要求与目的:

1.lab0主要是对一些工具使用的熟悉,文本编辑三剑客grep awk sed最基本的功能
2.对Git的简单原理和拓展指令熟悉使用
3.命令行运用,可执行文件边写

实验感受

1.使用命令行虽不及图形操作直观方便,但是更加简洁,对git版本控制的理解也会进一步加深,需要在抽象能力与文件管理能力
2.对c语言文件一步一步成为可执行文件的理解进一步加深,比如在预处理的时候也是需要头文件的,这是只是声明,在链接的过程中才会定义。
3.使用命令行处理文本时也会更加方便简洁,是一个很好使用的工具。
4.无论是编程还是都要保证每一个字符每一条命令的正确性。

OS-lab0
https://etherialize.github.io/2023/03/18/OS-lab0实验报告/
作者
HZY
发布于
2023年3月18日
许可协议