Why do people use: if [ "x$FOO" = "x" ] .... ?
Bill Stewart
wcs at ho95b.UUCP
Tue Apr 9 15:37:49 AEST 1985
I've seen a lot of Bourne shell scripts that test for
blank variables using the construct
if [ "x$FOO" = "x" ]
Why the x's? If you leave out the quotes, then the test dies if $FOO
is empty, but why not just use
if [ "$FOO" = "" ]
or
if [ -z "$FOO" ]
I've seen this construct in new code as well as old, from reputable
programmers. I've checked a few obscure cases like
FOO='`echo You Lose!!`'
but even they don't die. Is this just another superstition, like
sync; sync; sync;
or am I forgetting something stupid and obvious?
Thanks;
Bill Stewart, AT&T Bell Labs, Holmdel NJ
{ihnp4,allegra,cbosg}!ho95c!wcs
More information about the Comp.unix
mailing list