加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

shell脚本 :<<   :>  重定向 空指令

(2013-09-24 15:17:54)

冒号在shell中表示空指令。
原文如下:
:
null command [colon]. This is the shell equivalent of a "NOP" (no op, a do-nothing operation). It
may be considered a synonym for the shell builtin true. The ":" command is itself a Bash builtin, and its exit status is true (0).

所以:
: > file 用于清空文件
下面这种形式是Here Document的一种用法,用于注释一段代码块
:<<BLOCK
...
segment
...
BLOCK

http://zhidao.baidu.com/link?url=V1O6LQbnSa8hs8bZx0Dqpyxn9NyDZ4uNIZ2HJH1qLhQw4MSB1ODMGEADy_uI2CZxfz_iR3q1qbqEZeZ_WEVaq_

重定向 >  >>  <  << 两个表示追加


http://www.linuxidc.com/Linux/2012-12/76450.htm $ who > file
$ cat file1 file2 >> file3
$ mail tom < file
$ find / -name file -print 2> errors
$ (find / -name file -print > /dev/tty) >& errors
说明:
1、命令who的输出从终端被重定向到file。
2、命令cat的输出(连接file1和file2)被附加到file3尾部。
3、file的输入被重定向到mail程序,也就是说,file的内容被送给用户tom。
4、find命令的所有错误都被重定向到文件errors。输出则发往终端。
5、find命令的所有错误都被重定向到文件errors。输出则发往终端。
shell脚本下所有的重定向输入输出均可采用此方式操作。


0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有