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
Code language: Bash (bash)

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments