首页 > 编程语言 > Shell > Shell编程-使用echo创建文件并追加内容-含代码
2019
06-06

Shell编程-使用echo创建文件并追加内容-含代码

echo命令常用的用法是在终端打印字符串。我们还可以将字符串打印到我们自定义的文件中,即重定位。

例1:

exbot@ubuntu:~/liyijun$ echo "this is my test" > a.txt
exbot@ubuntu:~/liyijun$ cat a.txt
this is my test

我们使用“>”符号重新创建一个a.txt文档,并且将字符串打印到文档里。

我们再接着执行追加的命令:(>>)

exbot@ubuntu:~/liyijun$ echo "this is my second add" >> a.txt
exbot@ubuntu:~/liyijun$ cat a.txt
this is my test
this is my second add

例2:
在u-boot的代码里有如下几句话:大家可以加深一下印象

echo "ARCH   = $2" >  config.mk
echo "CPU    = $3" >> config.mk
echo "BOARD  = $4" >> config.mk

得到的结果是:

ARCH   = arm
CPU    = s5pc11x
BOARD  = x210

 

最后编辑:
作者:游戏创作者大陆

留下一个回复

你的email不会被公开。