>>重定向是什么 做?


16

什么时候应该>|用于将输出重定向到文件而不是>

当我看到这时,给出的解释是它可以确保首先截断目标文件。但是我认为>已经暗示了这一点。

是否>|有用?

Answers:


16

这是noclobber选项的显式绕过。

这样,即使已noclobber设置,您也可以覆盖文件。

参见http://mywiki.wooledge.org/NoClobber

来自man bash

如果重定向运算符为>,并且已启用内置内置集的noclobber选项,则如果存在其名称由word扩展产生的文件并且该文件是常规文件,则重定向将失败。如果重定向运算符为> |,或者重定向运算符为>,并且未启用set内置命令的noclobber选项,则即使存在以word命名的文件,也会尝试进行重定向。


8

来自man bash

         -C      If set, bash does not overwrite an  existing  file  with
                  the  >,  >&,  and <> redirection operators.  This may be
                  overridden when creating output files by using the redi
                  rection operator >| instead of >.
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.