Vivek Goel Vivek Goel - 1 year ago 132
Linux Question

Bash ignoring error for a particular command

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 ?

Answer Source

The solution:

particular_script || true


$ cat /tmp/

set -e

echo ein
particular_script || true
echo zwei
echo drei

$ bash /tmp/

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 (with pipefail off it must the last one).

$ set -o pipefail
$ false | true ; echo $?
$ set +o pipefail
$ false | true ; echo $?
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download