做什么>!和>>!在 tcsh 中执行
在正常的 bash 重定向中, >
将标准输出重定向到文件,如果存在则覆盖,而 >>
将标准输出重定向到文件,如果存在则追加。
在 tcsh (c shell) 脚本中,我发现使用了运算符 >!
>>!
。这个运营商是做什么的? tcsh 也有 >
和 >>
运算符,那么有什么区别呢?
In normal bash redirection >
redirecting standard output to a file, overwriting when it exists and >>
redirecting standard output to a file, appending when it exists.
In a tcsh (c shell) script I found the operators >!
>>!
being used. What do this operators do? tcsh does also have the >
and >>
operators, so what is the difference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 tcsh 重定向中!符号表示即使设置了
noclobber
也会覆盖现有文件。换句话说,如果设置了 noclobber,则:
cmd > file
会将stdout
写入 filecmd >, 如果文件存在
cmd>>, file
会将stdout
附加到 filecmd >>> 如果文件不存在
cmd>, 文件
将会失败! file 会将stdout
写入 file,覆盖任何现有文件cmd >>! file
会将stdout
附加到 file,如果文件尚不存在则创建该文件如果
noclobber
是 not然后设置!没有效果:cmd > file
会将stdout
写入 file,覆盖任何现有文件cmd >> file
会将stdout
附加到 filecmd >! file
会将stdout
写入 file,覆盖任何现有文件cmd >>! file
会将stdout
附加到 fileIn tcsh redirection the ! symbol means overwrite the existing file even if
noclobber
is set.In other words, if noclobber is set then:
cmd > file
will writestdout
to file if file does not existcmd > file
will fail if file existscmd >> file
will appendstdout
to file if file existscmd >> file
will fail if file does not existcmd >! file
will writestdout
to file, overwriting any existing filecmd >>! file
will appendstdout
to file, creating the file if it does not already existIf
noclobber
is not set then the ! has no effect:cmd > file
will writestdout
to file, overwriting any existing filecmd >> file
will appendstdout
to filecmd >! file
will writestdout
to file, overwriting any existing filecmd >>! file
will appendstdout
to file在某些情况下,感叹号会禁止检查写入的文件类型。
引用 tcsh 手册页:
The exclamation mark suppresses the check for the type of file being written to in certain cases.
To quote the tcsh man page: