使用cat命令输出大段字符

混江龙づ霸主 提交于 2020-02-02 02:30:33

Shell中EOF说明: 

Shell中通常将EOF与 << 结合使用,表示后续的输入作为子命令或子Shell的输入,直到遇到EOF为止,再返回到主调Shell。
可以把EOF替换成其他东西,意思是把内容当作标准输入传给程序。

回顾一下<<的用法。当shell看到<<的时候,它就会知道下一个词是一个分界符。在该分界符以后的内容都被当作输入,直到shell又看到该分界符(位于单独的一行)。这个分界符可以是你所定义的任何字符串。

 

cat命令:

       Concatenate FILE(s), or standard input, to standard output.

//将文件或者标准输入,输出到标准输出

 

示例脚本如下:

root@localhost ~]# cat test3.sh 
#!/bin/bash
dir="/root"
if [ -d $dir ];then
cat<<EOF
this is a test.
directory $dir exists.
this is the third line.
EOF
fi
[root@localhost ~]# 
[root@localhost ~]# ./test3.sh 
this is a test.
directory /root exists.
this is the third line.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!