Execution of subsequent commands after a command crashes.

王伟 <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <CAPGy_BZiE4RgZCSqQU1eikOGB4kjzu-5=AxE7GLkbK9O+RL69g@mail.gmail.com>
#!/usr/bin/env bash

test_crash ()
{
a=$((009+1))
}

test_crash
if [[ $? -ne 0 ]] ; then
    echo "case 1"
fi

if ! test_crash ; then
    echo "case 2"
fi

test_crash || echo "case 3"

{ test_crash ; } || echo "case 4"

exit 0

The code above shows the different results of several methods when a
function crashes due to a syntax error.

pc@DESKTOP-0MVRMOU UCRT64 /d/code$ bash test_bash_broke.sh
test_bash_broke.sh: line 5: 009: value too great for base (error token is
"009")
case 1
test_bash_broke.sh: line 5: 009: value too great for base (error token is
"009")
test_bash_broke.sh: line 5: 009: value too great for base (error token is
"009")
test_bash_broke.sh: line 5: 009: value too great for base (error token is
"009")
pc@DESKTOP-0MVRMOU UCRT64 /d/code$

Why is the exception branch executed only in the case of $?, and skipped in
all other cases?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.