Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1710191
  • 博文数量: 362
  • 博客积分: 10587
  • 博客等级: 上将
  • 技术积分: 4098
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-10 18:15
文章分类

全部博文(362)

文章存档

2014年(1)

2013年(58)

2011年(115)

2010年(112)

2009年(76)

分类:

2009-10-29 15:55:08

#!/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。
阅读(558) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~