[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: compile trouble
From: |
Ben Pfaff |
Subject: |
Re: compile trouble |
Date: |
Thu, 26 May 2011 07:55:51 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
John Darrington <address@hidden> writes:
> This seems to be a problem with non bash shells expanding
> string comparisons wrong.
Can you explain? Where do you see evidence of that?
> ie we need to write "test x$foo = xyes" instead of
> "test $foo = yes" .
test "x$foo" = xyes is safer. There are two issues:
- Double quotes protect $foo from shell word splitting,
so that if $foo has a space in it you still end up with
just one word.
- The reason for the leading "x" is different. It is
explained in the Autoconf manual:
Similarly, Posix says that both `test "STRING1" =
"STRING2"' and `test "STRING1" != "STRING2"' work
for any pairs of strings, but in practice this is
not true for troublesome strings that look like
operators or parentheses, or that begin with `-'.
It is best to protect such strings with a leading
`X', e.g., `test "XSTRING" != X' rather than `test
-n "STRING"' or `test ! "STRING"'.
In some circumstances you can omit both. A fair amount of
Autoconf code does that, because it knows that $foo must already
be set to some safe string (e.g. to exactly "yes" or "no").
> There are places (both in our configure.ac and in gnulib - in
> particular the include_next module) where this is not happening.
> I sent a patch to the gnulib list partially fixing the
> problem, but unfortunately got a somewhat aggressive response
> - "We cant apply patches that make things less reliable".
The only examples I see of "test" in gnulib/m4/include_next.m4
are the case where the variable should already be set to a safe
string. Can you point out an example that you think is wrong?
> I don't know why they think it would do that. I've not
> found a sufficient length of time where I've been in the
> correct mood to compose a reply yet.
I know how that goes, sometimes (but not usually with that
mailing list).
I don't recall that discussion there, do you have a pointer?
Thanks,
Ben.
--
Ben Pfaff
http://benpfaff.org