我认为这是某种ioredirect,但它看起来不同于手动的例子。 通常,我们可以通过以下行redirect脚本的stdout:
exec 1> /var/log/a.log
但是我在脚本中看到了这一行:
exec &> /var/log/a.log
这里“&”的含义是什么? 它是stdout和stderr吗?
谢谢,詹姆斯
你的猜测是对的。
exec >filename命令将stdoutredirect到指定的文件。 这会将通常会转到stdout所有命令输出发送到该文件。 command &> filename将command &> filename的stdout和stderrredirect到filename。 实际上, command &>file是另一种forms的command > file 2>&1 (在版本4,最终版本之前的Bourne Shell中,或在Debian / Ubuntu中使用的标准shell Debian Almquist shell中不可用):
& charachter是做什么的? 在这里很好地解释:
在从csh(C shell)派生的shell中,语法会将
&(&符号)字符附加到redirect字符,从而获得相似的结果。 原因是为了区分名为'1'和stdout的cat file 2>1,即cat file 2>1与cat file 2>&1。 在第一种情况下,stderr被redirect到一个名为“1”的文件,在第二个stderr被redirect到stdout。
阅读更多关于I / Oredirect的信息:
http://www.tldp.org/LDP/abs/html/io-redirection.html
http://www.tldp.org/LDP/intro-linux/html/sect_05_02.html#sect_05_02_01