Bash – how to stop at error

To stop a bash script at first error use set -e. To undo it use set +e.

set +e
ls -l /opt/non_existing_dir1
set -e
echo "I will be printed"
ls -l /opt/non_existing_dir2
echo "I will not be printed"
Env: GNU bash, version 4.3.11

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments