Shell set command

In a summary, set is a built in shell command. It supports many flags which can be opened by - and closed by +.

I have seen set -e and set -x frequently. Let’s see how the commands work.

set -e

If this flag opened, shell execution will exit immediately when a command exists with non-zero(failed) status. Commands in script are executed one by one even previous one failed. If this flag is set, the script will stop when failed. Below is an illustrative example.

set -x

This flag will print out commands and parameters during script execution. It’s useful for debugging purpose. Use set +x to turn off the feature. Remember to turn off before credential related commands in case critical info leaked.