原文: http://blog.sina.com.cn/s/blog_6aa1784101012caf.html
最近使用Shell编程编辑文件的时候,学习到了Here Document。感觉不错,分享给大家。
$ touch base.txt
$ ed base.txt
a
this is line1.
this is line2.
this is line3.
this is line4.
.
wq
$ ed base.txt
a
this is line1.
this is line2.
this is line3.
this is line4.
.
wq
#!/bin/sh
ed base.txt <<!ED1_JEREMIAH!
3
d
i
this is line 3 new.
.
w
q
!ED1_JEREMIAH!
ed base.txt <<!ED1_JEREMIAH!
3
d
i
this is line 3 new.
.
w
q
!ED1_JEREMIAH!
$ sh ed_file.sh && catbase.txt
60
this is line3.
65
this is line1.
this is line2.
this is line 3 new.
this is line4.
60
this is line3.
65
this is line1.
this is line2.
this is line 3 new.
this is line4.
$ mysql -u root
Welcome to the MySQLmonitor.
Commandsend with ; or \g.
Your MySQL connection id is 1257
Server version: 5.1.35-community MySQL Community Server(GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement.
mysql> use mysql
Reading table information for completion of table and columnnames
You can turn off this feature to get a quicker startup with-A
mysql> select * fromuser;
mysql> exit
Bye
Welcome to the MySQLmonitor.
Your MySQL connection id is 1257
Server version: 5.1.35-community MySQL Community Server(GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement.
mysql> use mysql
Reading table information for completion of table and columnnames
You can turn off this feature to get a quicker startup with-A
mysql> select * fromuser;
mysql> exit
Bye
#!/bin/sh
mysql -u root <<!ED2_JEREMIAH!
use mysql
select * from user;
exit
!ED2_JEREMIAH!
mysql -u root <<!ED2_JEREMIAH!
use mysql
select * from user;
exit
!ED2_JEREMIAH!
sh mysql_access.sh
本文出自 “海狗哥的流媒体空间”博客,请务必保留此出处http://jeremiah.blog.51cto.com/539865/339211