This short article will demonstrate how to check whether a string variable is empty in Bash and other Shell scripts in Linux, with examples.
Bash operators are the symbols and expressions that perform comparisons, assignments, and arithmetic.
The -z Bash Operator
The -z operator returns true if a string variable is null or empty.
How the use the -z Bash Operator
MY_STRING="" if [ -z $MYSTRING ] then echo "String is empty" else echo "String is not empty" fi
For more Shell scripting tips, check out or Bash/Shell scripting articles!