test "x$a" = "x$b" (Re: bourne shell query)
Felix Lee
flee at guardian.cs.psu.edu
Sat Sep 8 09:39:49 AEST 1990
> Why is even the "x" method necessary? My system's Bourne shell
> (a port of V.3.2's sh) doesn't have any problem handling '='
Modern Bourne shells appear to parse around '='. This makes cases
like this:
test -f = -f
work, but watch out for these:
eq='='
hy='-f'
test "$eq"
test "$hy"
test -l "$eq"
test -l "$eq" -lt 8
test -f "$eq"
test "$hy" = -a
test -f "$eq" -a ! -x "$eq"
The way "test" parses its arguments doesn't appear to be documented.
Fortunately, it doesn't take more than an hour to puzzle it out.
Unfortunately, fixing the above expressions to work no matter what the
value of $eq or $hy gets messy.
--
Felix Lee flee at cs.psu.edu
More information about the Comp.unix.shell
mailing list