To check if a string is empty/null or not use -n string or -z string with if condition.
-n string will return true if string is not empty/null.
-z string will return true if string is empty/null.
Example:
str="abc" if [[ -n $str ]] ; then echo "not empyt/null"; fi
Since str is not empty, above command will return not empyt/null.
str="" if [[ -z $str ]] ; then echo "empyt/null"; fi
Since str empty, above command will return empyt/null.
-Sany
Hi Sany,
do we really need the double square brackets?
yes, they are must.
No they are not…. single brackets would work as well