echo多行到html文件,科学网—将多行内容通过cat重定向输出至文件 - 谭月茜的博文...

初学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_

原理不明。求教。

转载本文请联系原作者获取授权,同时请注明本文来自谭月茜科学网博客。

链接地址:http://blog.sciencenet.cn/blog-747197-767699.html

上一篇:Stitch MAF blocks: generate multiple species alignment

下一篇:去除从Windows上传文件至Linux系统时产生的回车换行符

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值