How to check if null in bash

Expanding on the previous bash not null post to check if a string is null

String='' # Zero-length ("null") string variable. 

if [ -z "$String" ] 
then 
 echo "\$String is null." 
else 
 echo "\$String is NOT null." 
fi # $String is null. 

Justin Kelly

Justin Kelly

Web Developer, Business Analytics, Data Engineer specialising in PHP, ReactJS, Tableau, AWS RedShift and Matillion ETL

Based in Melbourne, Australia

Feel free to contact me justin@kelly.org.au or _justin_kelly

Leave a comment

Name Notify me of replies by email.