Quantcast
Channel: How to determine if a bash variable is empty? - Server Fault
Viewing all articles
Browse latest Browse all 16

Answer by MikeyB for How to determine if a bash variable is empty?

$
0
0

If you're interested in distinguishing the cases of set-empty versus unset status, look at the -u option for bash:

$ set -u
$ echo $BAR
bash: BAR: unbound variable
$ [ -z "$BAR" ] && echo true
bash: BAR: unbound variable
$ BAR=""
$ echo $BAR

$ [ -z "$BAR" ] && echo true
true

Viewing all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>