[Bash] Test whether a string is empty

Created on November 30, 2026

Use -z to test whether a string has zero characters. The following example enters the first branch because NAME is empty.

NAME=""
if [ -z "$NAME" ]; then
  echo "NAME is empty"
else
  echo "NAME is not empty"
fi

Output

NAME is empty
Bash Shell command