Subject: Re: simple shell test question
To: Jim Breton <jamesb-netbsd@alongtheway.com>
From: B. James Phillippe <bryan-spamtrap2@darkforest.org>
List: netbsd-users
Date: 06/05/2002 23:36:59
On the elevated day of Jun 6, Jim Breton wrote:

> 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?
...
> I have checked two books in my stash and neither of them mentions any use
> of this syntax that I can see.

As others have already pointed out the good reasons to do this, I won't
comment on that.  However, regarding the "books in my stash" comment, the
funny coicidence is that I was just working on a shell script today that
had a similar problem (*) and came across this (your) very query, answered
in my UNIX Power Tools.[1]  For anyone that doesn't have it, this is the
absolute Bible of UNIX.  Over 1100 pages[2] of easily indexed meat.

(*) The script tested $PWD, which is not set in non-login Bourne shells
(e.x. from crond).

[1] Section 48.04, 48.05
[2] I'm looking at the first edition, copyright '93; I think there is a
newer one

-bp
--
# bryan_at_darkforest_dot_org
# Software Engineer