[prog] bash: string comparisons in conditionals
riccarda.cassini at gmx.de
Thu Apr 22 09:27:21 EST 2004
Daniel <lc-programming at nada.refused.cc> wrote:
> On Mon, Apr 19, 2004 at 05:02:13PM +0200, Riccarda Cassini wrote:
> > When looking at other people's scripts, I sometimes see constructs like
> > if [ "x$1" = "x" ]
> > I understand that adding identical substrings to both sides of the
> > comparison doesn't really change the outcome of the test, but why is
> > this necessary? Or, if it isn't necessary, why are many people (which
> Well, [ "$1" = "" ] and [ -z "$1"] is semantically the same, but
> some people prefer the first way, because it's more readable.
> Afair, the strings are prefixed with "x", to be compatible with older
> (very old) versions of the test programm, which used to fail with
> [ "" = "" ].
I knew there must be some reason, other than people finding it fancy to
stick in some additional x'ses here and there... Thanks for mentioning it.
Has this bug (or feature) still any practical relevance nowadays?
(with nowadys I mean anything stretching back for, let's say, 5 years
"Sie haben neue Mails!" - Die GMX Toolbar informiert Sie beim Surfen!
Jetzt aktivieren unter http://www.gmx.net/info
More information about the Programming