Answer the question
In order to leave comments, you need to log in
When redirecting output to a file, how to NOT create a file if there is no output?
./myscript.sh 2>err.log
When the command is executed, the err.log file is created
How to cancel the creation of the file if nothing was written to stderr?
In my script, I delete the err.log file before executing the rest of the commands. I check the file size at the end of the script. If there is no file content, then I delete it after executing all commands.
Answer the question
In order to leave comments, you need to log in
No way.
When you open a redirect, you touch the file.
You can write all sorts of perversions, but it's easier to delete the file after execution if it is empty.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question