What would set +e and set -x commands do in the context of a shell script

bashshell

I'm looking at a shell script that contains the following:

set +e
set -x

I see that the commands are used to "assign a value to a shell variable". But in this context I don't understand the usage.

https://afni.nimh.nih.gov/pub../pub/dist/edu/data/CD.expanded/AFNI_data6/unix_tutorial/misc/unix_commands.html#set

Best Answer

That style of set command sets or unsets shell options. Confusingly - sets the option and + unsets the option.

option "e" makes the shell script error out whenever a command errors out. It's generally a good idea to have it enabled most of the time.

option "x" makes the shell print out commands after expanding their parameters but before executing them. Useful when debugging but can get overwhelming sometimes.

See https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html for more (that documentation is for bash but many of the features are common across many shells)

Related Question