What does -z mean in Bash?
BashBash Problem Overview
I'm looking at the following code:
if [ -z $2 ]; then
echo "usage: ...
(The 3 dots are irrelevant usage details.)
Maybe I'm googling it wrong, but I couldn't find an explanation for the -z
option.
Bash Solutions
Solution 1 - Bash
-z string
True if the string is null (an empty string)
Solution 2 - Bash
-z
string is null, that is, has zero length
String='' # Zero-length ("null") string variable.
if [ -z "$String" ]
then
echo "\$String is null."
else
echo "\$String is NOT null."
fi # $String is null.
Solution 3 - Bash
Solution 4 - Bash
The expression -z string
is true if the length of string is zero
.