When one of my programs returns with a non-zero exit code, I want to avoid redirecting its output. Is this possible, and, if so, how do I do this?
My failed attempt:
echo foo > file
false | cat > file
this results in file
being empty. The behaviour I want is to only adjust file
when the program succeeds.
I also wonder whether it is possible do only update a file if the output is non-empty, without using multiple files.