bash - set -e makes function stop running early? -
i have function seems break when turn on errors set -e . suspect working intended can't see i'm doing wrong. here function: #!/usr/bin/env bash set -e my_function() { base_dir="/tmp/test" if [ ! -d $base_dir ]; echo "creating $base_dir" mkdir -p $base_dir touch $base_dir/some-file.txt fi is_edited=$(grep "foo" $base_dir/some-file.txt) if [ ! -z $is_edited ]; cd $base_dir echo "doing stuff" docker run --rm debian ls fi echo echo "done" echo } my_function with set -e flipped on, function returns seemingly without hit echo statements. set -e turned off, echo statements hit. happening , how fix this? try using: is_edited=$(grep "foo" $base_dir/some-file.txt || test $? -eq 1) the exit status of grep 0 if found match, 1 if didn't find match, , 2 if got actual error. if there's no match foo in fi...