Subject: Re: simple shell test question
To: Jim Breton <jamesb-netbsd@alongtheway.com>
From: Rob Windsor <windsor@warthog.com>
List: netbsd-users
Date: 06/06/2002 00:54:43
On Thu, 06 Jun 2002 05:48:59 -0000, verily did Jim Breton write:

> In my travels I have often seen shell syntax like the following:

> [ x"$VAR" != x"value" ]

> What is the point of doing that instead of the following?

> [ "$VAR" != "value" ]

> Does the 'x' have some special meaning?  (If so, are there any other
> characters with special meanings?)

> I have checked two books in my stash and neither of them mentions any
> use of this syntax that I can see.

In the old (cough, "SunOS") days, "" was processed by test(1) such that if 
$VAR was empty, test(1) would barf (erroring out your script), only seeing 
[ != "value" ].  The fix/hack was to put a prefixing `x' ahead of the 
quotes.

I might add that seeing your example above merely means that someone was 
in the habit of using x"$foo".  SunOS, at one point, also didn't recognize 
the "!=" operator.  Instead, you had to use [ ! x"$VAR" = x"value" ].

Rob++
----------------------------------------
Internet: windsor@warthog.com                             __o
Life: Rob@Carrollton.Texas.USA.Earth                    _`\<,_
                                                       (_)/ (_)
The weather is here, wish you were beautiful.