Skip to content

Instantly share code, notes, and snippets.

@aergonaut
Last active December 4, 2018 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aergonaut/15fecbb56afcbb43471d0dffc4eb1f00 to your computer and use it in GitHub Desktop.
Save aergonaut/15fecbb56afcbb43471d0dffc4eb1f00 to your computer and use it in GitHub Desktop.

Demonstrating behavior of exit in shell scripts.

The desired behavior is that the script b.sh is run in the middle of a.sh or c.sh. a.sh and c.sh only differ in how they call b.sh.

Running a.sh has the following output:

$ ./a.sh
starting a.sh
starting b.sh

Note that the final line in a.sh is never executed.

Running c.sh has the following output:

$ ./c.sh
starting c.sh
starting b.sh
ending c.sh

Now the final line in c.sh is run.

echo "starting a.sh"
. ./b.sh
echo "ending a.sh"
echo "starting b.sh"
exit
echo "starting c.sh"
./b.sh
echo "ending c.sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment