[root@master tmp]# cat <<eof>log.txt # 覆盖的方式输入到log.txt
> ..........
> eof
或
[root@master tmp]# cat >log1.txt <<eof
> ..........
> eof
eof部分都必须使用"<<eof",它表示here document,此后输入的内容都作为一个document输入给cat。既然是document,那就肯定有document结束符标记document到此结束,结束符使用的是here document后的字符,例如此处为eof。其实不使用eof,使用其他字符也是一样的,但document的结束符也必须要随之改变。
[root@master ~]# cat <<abcx
> 123
> 345
> abcx
123
345
另一方面,>log1.txt表示将document的内容覆盖到log1.txt文件中,如果是要追加,则使用>>log1.txt。
[root@master tmp]# cat >>log1.txt <<eof
> this is stdin character first!
> eof
或
[root@master tmp]# cat <<eof>>log1.txt
> this is stdin character first!
> eof
————Blueicex 2020/03/07 21:40 blueice1980@126.com