DEV Community

Cover image for Quick Test Your Bash Shell

Quick Test Your Bash Shell

vumdao profile image Vu Dao ・1 min read

Challenge Yourself

See following bash code and answer what the output is without running it

set -e

mutex_test() { return -23; }


echo $?

echo "Done"
Enter fullscreen mode Exit fullscreen mode

🌠 Blog · Github · Web · Linkedin · Group · Page · Twitter 🌠

Discussion (2)

bobbyiliev profile image
Bobby Iliev

I use the shellcheck tool as described here:

You can use their website directly or you could install the CLI tool as well.

It is very handy, it gives you some suggestions on some best practices too.

moopet profile image
Ben Sinclair

If you run it via bash or make it executable and run it, it'll presumably either display nothing (which is what I expect to happen because -23 is non-zero and set -e means bomb out whenever anything returns non-zero) or possibly display -23 (if it doesn't count in a function, but I don't think that's the case).

If you source/dot the file to run it in the current context, you'll end up closing your shell.

Forem Open with the Forem app