Skip to content

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)

See also  How to Change the Hostname on Linux
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x