3 ms·
I shell languages I do this a lot. if "x$VARIABLE" == "x" because it handles the cases where $VARIABLE is undefined or multiple words without vomiting all
by danielweber 13y ago
I shell languages I do this a lot.
if "x$VARIABLE" == "x"
because it handles the cases where $VARIABLE is undefined or multiple words without vomiting all over the place.
- viraptor 13y agoI hate when people do that because it's not needed at all. The quoting already fixes everything. if [[ "$VARIABLE" == "" ]] or even better if [ -z "$VARIABLE" ] will handle undefined, empty and multiple words just fine.
- twic 13y agoUnless you're running with -u, which you should be, in which case it will blow up on an undefined variable. To treat undefined as empty, you want: if [[ -z "${VARIABLE:-}" ]]