Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jun 292012

How to ignore error in Bash script


We have learned in the past on how to show the exit status of a given command.

But is it possible ignore the error and return normal exit code even the command has failed?

Yes, pipe "|| true" to the end of command, e.g.

# foo || true
-bash: foo: command not found
# echo $?

As you can see even the command foo was not found, our last exit code is still zero.

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>