how to find variable is empty in shell script
+1
A:
Presuming bash:
var=""
if [ -n "$var" ]; then
echo "not empty"
else
echo "empty"
fi
ChristopheD
2010-06-17 11:04:39
glenn jackman
2010-06-17 12:02:48
@glenn jackman: good comment; it's true that `-z` is closer to what was asked. Jay has put this in his answer so I'll refrain from updating mine and leave this up as is.
ChristopheD
2010-06-17 19:10:10
+2
A:
In bash at least: if [[ -z "$var" ]]
the command line "man test" is your friend.
Jay
2010-06-17 17:09:32
A:
[ "$variable" ] || echo empty
: ${variable="value_to_set_if_unset"}
pixelbeat
2010-06-18 10:46:45