bashexit

How to exit all the calling scripts in bash?


Lets say I have the following scripts

a.sh

echo in a
if test 1 -ne 2; then
        echo oops
        exit 1
fi

b.sh

echo in b
./a.sh
echo in b 2

When running b.sh, I want it to exit if a.sh exited. How do I do this?

(The current output is

in b
in a
oops
in b 2

And that's not what I want)

Thanks, Rivka


Solution

  • check return status of a command, corresponding variable is $?. alternatively, you can short-circuit using command || exit