17

When should you use >| for redirecting output to a file instead of just >?

The explanation given when I was shown this was that it guaranteed the target file was truncated first. But I thought > already implied that.

Is >| useful?

2 Answers 2

17

It's an explicit bypass of noclobber option.

That way, you can overwrite the file even with noclobber set.

See http://mywiki.wooledge.org/NoClobber

From man bash :

If the redirection operator is >, and the noclobber option to the set builtin has been enabled, the redirection will fail if the file whose name results from the expansion of word exists and is a regular file. If the redirection operator is >|, or the redirection operator is > and the noclobber option to the set builtin command is not enabled, the redirection is attempted even if the file named by word exists.

0
9

From 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 >.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .