Cat命令结合重定向功能实现文本内容写入

Cat命令结合重定向功能实现文本内容写入

将stdin标准输入的内容重定向到test文件(以覆盖文件内容的方式,若此文件不存在,则创建之),且当stdin中含有EOF时完成写入:

[root@localhost ~]# cat > test << EOF
> this is first line 
> this is second line
> this is thrid line
> this is fourth line
> EOF
[root@localhost ~]# cat test
this is first line 
this is second line
this is thrid line
this is fourth line

将stdin的内容追加到已存在的test文件,且当stdin中含有EOF时完成写入:

[root@localhost ~]# cat >> test << EOF
> this is five line
> this is sixth line
> EOF
[root@localhost ~]# cat test
this is first line 
this is second line
this is thrid line
this is fourth line
this is five line
this is sixth line

说明:以上的EOF可以替换为你想要的其它字符串。

猜你喜欢

转载自blog.csdn.net/networken/article/details/80564824