Select Page

How to check if a Bash variable is empty

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

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.