#!/bin/sh
cat << !FUNKY!
hello
this is a here
document
!FUNKY!
即可输出如下信息:
hello
this is a here
document
here文档的另一个用法:
1)下面是a_text_file的内容
that is line 1
that is line 2
that is line 3
that is line 4
2)我们可以通过混合使用一个here文档和ed编辑器来修改这个文件。
#!/bin/sh
ed a_text_file << !FunkyStuff!
3
d
..\$s/is/was/
w
q
!FunkyStuff!
运行后的新文件内容如下:
that is line 1
that is line 2
that was line 4
解释下:脚本先调用ed编辑器并向它传递命令,先让它移动到第三行,然后删除该行,再把当前行(现在已经变成以前的第四行)的is替换为was。
阅读(576) | 评论(0) | 转发(0) |