here is the minimal code (tested on centos7 bash 4.2 and rocky8 bash 4.4):
#!/bin/bash
func1() {
echo a
echo b
cd asdfasdf123
echo "c: should not get here"
echo "d: should not get here"
}
main() {
echo "DEBUG: $FUNCNAME: LINENO=$LINENO"
exitcode=0
func1 || exitcode=1
echo "DEBUG: $FUNCNAME: LINENO=$LINENO"
func1
echo "DEBUG: $FUNCNAME: LINENO=$LINENO"
}
set -x
set -eu
main
- in the first call of
func1
: i am expecting the code to never print theecho c
line of code. but instead i see that the code does get to theecho c
line of code. - in the second call of
func1
: i see that the code does correctly exit when the error happens.
this is bad because i have a larger important shell program that gets an error early in the code and does not exit when i need the code to exit and instead keeps going even though the early operation did not do what i needed it to do.