“&!”的功能在csh中

时间:2018-06-15 14:18:24

标签: csh

a.csh是一个打印特定消息的c shell脚本。 以下几行有什么作用?

source a.csh > &! b.log

执行后,b.log文件包含a.csh的输出。但是“&!”的功能是什么?

1 个答案:

答案 0 :(得分:1)

>name将stdout重定向到name; >&将stdout和stderr重定向到name>!会覆盖noclobber设置,以防止意外覆盖现有文件。

可以将它们组合为>&!name,将stdout和stderr重定向到name,覆盖noclobber设置。

在您的示例中,>&!之间的空格使其看起来像是两个不同的运算符,但它只是>&!

另见man csh(搜索>&):

   > name
   >! name
   >& name
   >&! name
           The file name is used as standard output.  If the file does not
           exist  then it is created; if the file exists, it is truncated,
           its previous contents being lost.

           If the shell variable noclobber is set, then the file must  not
           exist  or  be  a  character  special  file (e.g., a terminal or
           `/dev/null') or an error results.  This helps prevent  acciden‐
           tal  destruction  of  files.  In this case the `!' forms can be
           used to suppress this check.  If notempty is given  in  noclob‐
           ber,  `>'  is  allowed  on  empty  files;  if  ask  is  set, an
           interacive confirmation is presented, rather than an error.

           The forms involving `&' route the diagnostic  output  into  the
           specified  file  as  well  as  the  standard  output.   name is
           expanded in the same way as `<' input filenames are.

(“诊断输出”对于stderr来说是csh-speak。)