The bash noclobber option prevents one from overwriting files with redirection. But sometimes I really want to. csh has a similar option and it can be over-ridden by putting a ! before the filenames. Is there any way to do this with bash?

link|improve this question

feedback

1 Answer

up vote 6 down vote accepted

Yes. Append | to the redirection operator to form >|. This is in § 3.6.2 of the Bash Reference Manual, q.v.

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 is not enabled, the redirection is attempted even if the file named by word exists.

Visit this tutorial about the noclobber option. It might be of help.

link|improve this answer
Thanks! I wish they had used the same syntax... – vy32 Nov 6 '11 at 12:32
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.