Thinking 0.1
执行
git status > Untracked.txt
,查询当前工作区的状态。此时工作区的状态是修改了README.txt
文件但未添加。>
表示输出重定向,将当前工作区的状态输出到目标文件Untracked.txt
中。add
命令表示将工作区的修改添加到暂存区,此时工作区的状态是修改了README.txt
文件且已添加到暂存区。>
表示输出重定向,将当前工作区的状态输出到目标文件Stage.txt
中。提交命令为
git commit -m "23373517"
cat Untracked.txt
,第二行显示Untracked files:
,说明在README.txt
新建的时候,其处于为未跟踪状态 (untracked)。cat Stage.txt
,第二行显示Changes to be committed:
,说明文件处于暂存区,等待提交。修改
README.txt
并将工作区状态保存到Modified.txt
后,输出的状态为Changes not staged for commit:
,与第一次add
前的状态不同,说明在修改README.txt
文件后其处于被修改状态(modified)
Thinking 0.2
add the file
:git add
stage the file
:git add
commit
:git commit
Thinking 0.3
git checkout --print.c
git checkout --print.c
git rm --cached print.c
Thinking 0.4
第一次
git log
第二次
git log
第三次
git log
第四次
git log
Thinking 0.5
echo first
echo second > output.txt
echo third > output.txt
echo forth >> output.txt
Thinking 0.6
command:
echo
命令后加单引号会将内容视为字面量字符串,不做任何扩展或替换,保留所有特殊字符和空格。#!/bin/bash touch test echo 'echo Shell Start...' > test echo 'echo set a = 1' >> test echo 'a=1' >> test echo 'echo set b = 2' >> test echo 'b=2' >> test echo 'echo set c = a+b' >> test echo 'c=$[$a+$b]' >> test echo 'echo c = $c' >> test echo 'echo save c to ./file1' >> test echo 'echo $c>file1' >> test echo 'echo save b to ./file2' >> test echo 'echo $b>file2' >> test echo 'echo save a to ./file3' >> test echo 'echo $a>file3' >> test echo 'echo save file1 file2 file3 to file4' >> test echo 'cat file1>file4' >> test echo 'cat file2>>file4' >> test echo 'cat file3>>file4' >> test echo 'echo save file4 to ./result' >> test echo 'cat file4>>result' >> test
result:
3 2 1
echo echo Shell Start
直接把“echo Shell Start”作为字符串输出如果在后面的内容加上反顿号,是将内部
echo
命令的输出作为外层echo
的输出,会输出”Shell Start”echo echo $c>file1
直接把“echo $c>file1”作为字符串输出如果在后面的内容加上反顿号,是将内部
echo
命令的输出作为外层echo
的输出,会输出 变量c的具体内容>file1
难点分析
Exercise 0.1
- 注意复制文件的命令
cp
和移动文件的命令mv
不同,mv
以后源目录下就不存在该文件了 - 提取AAA文件的第8行到BBB文件中:sed -n ‘8p’ AAA > BBB (安静模式-n,且仅输出不编辑,不写-i)
Exercise 0.2
rmdir
命令只能删除空目录,如果想要递归删除目录及其内容,需要使用rm -r ./"file$a"
。注意要使用双引号才能得到变量的值。
Exercise 0.3
寻找文件
file
中所有含有sign
字符串的行号使用grep
命令grep -n "$int" "$file" | awk -F: '{print $1}' > $result
awk
命令用来分割答案,只输出行号
Exercise 0.4
执行
make
命令时,默认执行当前目录下的makefile文件中的第一个命令makefile文件中可以执行另一个makefile文件的内容
$(MAKE) -C ./code
$(MAKE)
是一个特殊的变量,它在Makefile
中指向当前的make
命令-C
是make
的一个选项,表示改变目录执行make
本题文件树如下
csc/ │ ├── Makefile └── code/ └── Makefile └── fibo.c └── main.c
可以在csc目录下执行
make
,执行csc/code中Makefile文件的内容,省去一些麻烦注意头文件的依赖。
csc/code
中的fibo.c
和main.c
均引入头文件#include <fibo.h>
,但是csc/code中没有这个头文件,因此在编译时要加上头文件的目录,否则会提示找不到头文件csc/Makefile如下:
1 CFLAGS = -I./include # -I用来指定头文件的搜索路径,为当前目录下的include 2 all: 3 $(MAKE) -C ./code # 执行csc/code的Makefile 4 gcc $(CFLAGS) ./code/main.o ./code/fibo.o -o fibo # 在编译时加入头文件的环境变量 5 6 clean: 7 rm -f ./code/main.o 8 rm -f ./code/fibo.o
实验体会
写下实验过程中的体会。
lab0课下实验主要是练习一些指令,并不复杂,不过如果不够熟练的话就要经常翻看指导书或者是上网查找,比较浪费时间。
另外,实现同一个效果的途径可能很多,应该权衡最简便的方式。比如Exercise 0.4中csc/Makefile的编写可能有很多种方式,可以像我现在写的,也可以先cd到csc/code,再执行内部的Makefile文件。我个人认为一切从简比较好。
以及,在生成可执行文件时,可以先看看.c文件中的头文件在当前目录下是否存在,不过就算不存在,当你编译时它也会提醒你,再去添加头文件就好喽。
继续努力。
致谢
在撰写过程中,我参考了 YannaZhang 张杨 学姐的博客,感觉学到了很多,在此致谢。