20 Sep: "Force Overwrite" Bash Redirection Operator
There's a bash shell option, noclobber, that prevents overwriting existing files:
$ set -C # or set -o noclobber
When set bash will report an error if you try to redirect something to an existing file:
$ echo "hi" > test
bash: test: cannot overwrite existing file
You could check that the noclobber option is responsible for this by looking at what SHELLOPTS are active:
$ echo $SHELLOPTS
$ set | grep SHELLOPTS
You could unset noclobber, but instead, if you know better and know you want to overwrite, you could use the special >| redirection operator. From the bash man page:
"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."
$ echo "hi" >| test
If you want to see all the shell options that you can set, and what they do, run "help set".