[CLUE-Tech] bash: overwrite and redirect

David Anselmi anselmi at americanisp.net
Mon Feb 17 21:29:44 MST 2003


Jason S. Friedman wrote:
> I know that I can redirect stdout and stderr with the &>:
> 
> some command &> result_file
> #sends stdout and stderr to result_file
> 
> I know that I can overcome the noclobber setting with the |:
> 
> some command >| result_file
> # sends stdout to result_file, clobbering result if it exists
> 
> If I try to do both:
> some command &>| result_file
> 
> I get this error:
> -bash: syntax error near unexpected token `|'
> 
> What's a straightforward way to both redirect and force a clobber?

set +o noclobber

This is the default, unless you've done 'set -o noclobber'.

If you count on noclobber being set, do this:

some command >| result_file 2>&1

The &> or >& are just shorthand for this anyway.

Dave




More information about the clue-tech mailing list