Why do people use: if [ "x$FOO" = "x" ] .... ?
L.M.McLoughlin
lmcl at ukc.UUCP
Sat Apr 20 06:48:59 AEST 1985
In article <361 at ho95b.UUCP> wcs at ho95b.UUCP writes:
>
> I've seen a lot of Bourne shell scripts that test for
>blank variables using the construct
> if [ "x$FOO" = "x" ]
>
...
> if [ "$FOO" = "" ]
>or
> if [ -z "$FOO" ]
How about:
case "$FOO"
in
'') echo ALL GONE;;
*) echo Something here;;
esac
Unless you have '[' built into your shell this is generally a lot faster
but maybe less readable.
I too used to use the "x$VAR" type tests and kicked myself when I saw the
case equivalent in the rn sources.
More information about the Comp.unix
mailing list