How to Exit if a Bash Variable in Not Set


Sometimes you might want to exit a command if a variable is not set in Bash.

You can do this as follows:

if [ -z "$VARIABLE_NAME" ]; then echo "VARIABLE_NAME is not set"; exit 1; fi