B
B
Boris Dergachev2015-03-12 10:44:46
bash
Boris Dergachev, 2015-03-12 10:44:46

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

1 answer(s)
V
Vlad Zhivotnev, 2015-03-12
@froex

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 question

Ask a Question

731 491 924 answers to any question