[comp.unix.shell] test "x$a" = "x$b"

flee@guardian.cs.psu.edu (Felix Lee) (09/08/90)

> 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@cs.psu.edu