[prog] bash: string comparisons in conditionals

Riccarda Cassini riccarda.cassini at gmx.de
Sat Apr 24 11:10:38 EST 2004


Telsa Gwynne wrote:
On Fri, Apr 23, 2004 at 01:10:37PM +0200 or thereabouts, Riccarda Cassini
wrote:
> > Btw, if anyone knows whether there are similar debugging tools on those
> > platforms, I'd like to know... TIA.
> 
> strace on Linux does the same job as truss on Solaris. Does
> truss exist on AIX or HP-UX, perhaps?

Hi Telsa,

thanks for mentioning truss.  Although it doesn't seem to exist on
HP-UX and AIX, the info is still valuable, as I'm of course interested
in debugging tools for other platforms as well - you never know when
you'll need them...

Well, now knowing about truss, I did try to trace my test script on
a Solaris system to check whether 'test' is a builtin in /bin/sh as 
well. Same result as with bash on Linux: no exec()s for the test/[
calls whatsoever. (In contrast to bash, there doesn't seem to be a way
to force usage of external programs, other than by explicitly writing
/usr/bin/test).  While I was at it, I also ran the tests on some other
platforms.  The most ancient systems I could find were SunOS 5.5.1,
IRIX 6.2 and OSF1 V4.0.

The pattern is always the same: with a=-r, [ ! "$a" ] fails, while all
other tests, including [ "$a" = "" ] work without a problem.  Assuming
that any possible bugs related to 'test' have not been reinvented in
later versions again, I guess this more or less rules out any practical
relevance of having to do 'x'-prefixing on string comparisons (except
that there's a problem with *BSD systems - which I couldn't check).


> > [*] actually, on HP-UX there is some strace program, but it seems to be
> > doing something entirely different.  (I did a 'man strace', but what I
> > got is about the most incomprehensible manpage I've ever encountered so
> > far - haven't got the faintest idea what they're talking about... ;-)
> 
> "strace - write STREAMS event trace messages to standard output"?

:-)  The only meaning I can extract from this is that some messages are
being written to stdout. Probably it would help if I knew what streams
events are, or simply streams in the first place (btw, why is STREAMS
capitalized - some abbreviation for something else than streams?).
Reading on doesn't make it any clearer... ;-)
Anyway, I don't think I really *have* to know at the moment...
</being_silly>

> 
> http://www.freebsd.org/cgi/man.cgi is a wonderful thing.

useful stuff - especially if you don't have access to a specific
platform at the moment, some man pages on the system are missing for
some reason, or if you simply want to do historical analyses...

Thanks very much!

Riccarda



-- 
NEU : GMX Internet.FreeDSL
Ab sofort DSL-Tarif ohne Grundgebühr: http://www.gmx.net/dsl



More information about the Programming mailing list