I am using following options
set -o pipefail
set -e
In bash script to stop execution on error. I have 100 of script executing and I don't want to check return code of the script. But for a particular script I want to ignore the error. How can I do that ?
Instead of "returning true", you can also use the "noop" or null utility (as referred in the POSIX specs)
:
and just "do nothing". You'll save a few letters. :)Just in case if you want your script not to stop if a particular command fails and you also want to save error code of failed command:
code
I have been using the snippet below when working with CLI tools and I want to know if some resource exist or not, but I don't care about the output.
Just add
|| true
after the command where you want to ignore the error.The solution:
Example:
drei
will be never printed.Also, I want to add that when
pipefail
is on, it is enough for shell to think that the entire pipe has non-zero exit code when one of commands in the pipe has non-zero exit code (withpipefail
off it must the last one).More concisely:
From the POSIX specification regarding
set -e
(emphasis mine):