做什么>!和>>!在 tcsh 中执行

发布于 2024-11-25 06:24:00 字数 263 浏览 6 评论 0原文

在正常的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜血缘 2024-12-02 06:24:00

在 tcsh 重定向中!符号表示即使设置了 noclobber 也会覆盖现有文件。

换句话说,如果设置了 noclobber,则:

  • cmd > file 会将 stdout 写入 file
  • 如果 file 不存在cmd >, 如果文件存在
  • cmd>>, file 会将 stdout 附加到 file
  • 文件将失败如果 file 存在cmd >>> 如果文件不存在
  • cmd>, 文件将会失败! file 会将 stdout 写入 file,覆盖任何现有文件
  • cmd >>! file 会将 stdout 附加到 file,如果文件尚不存在则创建该文件

如果 noclobbernot然后设置!没有效果:

  • cmd > file 会将 stdout 写入 file,覆盖任何现有文件
  • cmd >> file 会将 stdout 附加到 file
  • cmd >! file 会将 stdout 写入 file,覆盖任何现有文件
  • cmd >>! file 会将 stdout 附加到 file

In 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 write stdout to file if file does not exist
  • cmd > file will fail if file exists
  • cmd >> file will append stdout to file if file exists
  • cmd >> file will fail if file does not exist
  • cmd >! file will write stdout to file, overwriting any existing file
  • cmd >>! file will append stdout to file, creating the file if it does not already exist

If noclobber is not set then the ! has no effect:

  • cmd > file will write stdout to file, overwriting any existing file
  • cmd >> file will append stdout to file
  • cmd >! file will write stdout to file, overwriting any existing file
  • cmd >>! file will append stdout to file
不…忘初心 2024-12-02 06:24:00

在某些情况下,感叹号会禁止检查写入的文件类型。

引用 tcsh 手册页:

如果设置了 shell 变量 noclobber,则该文件必须不存在或者是字符特殊文件(例如,终端或“/dev/null”),否则会产生错误。这有助于防止文件意外损坏。在这种情况下,“!”表单可用于抑制此检查。

The exclamation mark suppresses the check for the type of file being written to in certain cases.

To quote the tcsh man page:

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 accidental destruction of files. In this case the ‘!’ forms can be used to suppress this check.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文