Bash Shell Scripting

How to check if a Bash variable is empty

Written by Ian Carnaghan · 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
Written by Ian Carnaghan
I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment. Profile

Leave a Reply

Notify of