初学linux下的bashshell,是在 http://linuxcommand.org/ 。里面提到了利用cat命令输入多行内容,而不需要一行一个echo。例如将如下代码1写成代码2的形式会好看方便很多:
代码1
#!/bin/bash
# make_page - A script to produce an HTML file
echo ""
echo "
"echo "
"echo " The title of your page"
echo "
"echo ""
echo ""
echo "
"echo " Your page content goes here."
echo ""
echo ""
代码2
#!/bin/bash
# make_page - A script to produce an HTML file
cat << _EOF_
The title of your page
Your page content goes here.
_EOF_
语法形式:
command << token
content to be used as command's standard input
token
(*token是指任何字符串)
然而,使用过程中发现,如下代码3无法将这些内容通过cat重定向输出至文件:
代码3
#!/bin/bash
# make_page - A script to produce an HTML file
cat << _EOF_
The title of your page
Your page content goes here.
_EOF_ > newfile
经过胡乱摸索后发现,改为以下代码4便可以了:
代码4
#!/bin/bash
# make_page - A script to produce an HTML file
cat > newfile << _EOF_
The title of your page
Your page content goes here.
_EOF_
原理不明。求教。
转载本文请联系原作者获取授权,同时请注明本文来自谭月茜科学网博客。
上一篇:Stitch MAF blocks: generate multiple species alignment
下一篇:去除从Windows上传文件至Linux系统时产生的回车换行符