I have a bash script I want to self-destruct on execution. So far it works great but I'd like some final check that if no errors have occurred (any output to stderr), then go ahead and self destruct. Otherwise, I'd like to leave the script in tact. I have the code for everything except the error check. Not sure if I can just output err to a file and check if file is empty. I'm sure it's a simple solution.
How could I do this?
Thanks for any help.
set -ehas nothing to do with STDERR, it just deals with exit codes. Note though that just because a command prints to STDERR it doesn't mean that it has failed. A lot of commands just use it for logging. A command's exit code should indicate its success.