How to check if a Bash variable is empty

8 sec read

if [ -z "$VARIABLE" ]

If $VARIABLE is not set or empty the if statement above will return true, the -z option tests for a zero-length string, so whether $VARIABLE is not set or empty the ifstatement will return true

Last Updated On April 07, 2018

Leave a Reply

avatar
  Subscribe  
Notify of