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

REF:

http://www.runoob.com/linux/linux-shell-echo.html

朱友鹏老师课件

猜你喜欢

转载自blog.csdn.net/wwwlyj123321/article/details/81669342
今日推荐