Bash Variable Empty
Here’s how to check in Bash if a variable is empty or unset.
<pre lang="bash">
if [ -z "${VAR}" ];
then
echo 'do something'
else
echo 'do another'
fi
One liner
<pre lang="bash">
if [ -z "${VAR}" ]; then echo 'do something'; else echo 'do another'; fi
The inverse
<pre lang="bash">
if [ ! -z "${VAR}" ];
then
echo 'do something'
else
echo 'do another'
fi
<pre lang="bash">
if [ ! -z "${VAR}" ]; then echo 'do something'; else echo 'do another'; fi