Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

2 Answers

up vote 10 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.

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

Use | ("pipe") instead of ! ("bang"), as in:

echo done >| out

However, >|& and &>| don't work—if you want to override noclobber and redirect stderr, do it like this:

mixout stdout stderr >| out 2>&1
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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