SOURCES: klibc-kill_bashism.patch (REMOVED) - last change reverted...

Paweł Sakowski saq at pld-linux.org
Fri Sep 30 16:05:53 CEST 2005


On Fri, 2005-09-30 at 15:40 +0200, Arkadiusz Miskiewicz wrote:
> > >    echo '[ "foo" = "bar" -a "-u" = "zoo" ]'|/bin/sh
> > >    /bin/sh: <stdin>[1]: [: zoo: unexpected operator/operand
> > alternatives:
> > echo '[ "foo" = "bar" ] && [ "-u" = "zoo" ]'|/bin/sh
> > echo '[ "foo" = "bar" -a x"-u" = x"zoo" ]'|/bin/sh
> 
> The original test should work since "" is posix quoting and it should quote 
> -u, too I guess.

The quoting isn't kept when the arguments are passed to [, whether it is
a builtin or /usr/bin/[. You can use \"-u\" = \"zoo\" if you wish, to
the same effect as with x"...".

> bash, zsh work well with the original test. ksh doesn't not, sounds like ksh 
> bug.

More likely syntax ambiguity resolved differently by different parsers.
Looks like bash first matches the "X = Y" syntax rule and ksh: "-u Z".
In alternative #1 the same token sequence happens to match "X = Y" on
ksh too, but it's underspecified and not to be relied on. On
encountering "-u", [ is rightfully allowed to suppose it means "file is
suid". You can (and should) easily avoid ambiguity by prefixing any a
priori unknown strings with x (or anything not starting with -=!(] ).

-- 
Paweł Sakowski <saq at pld-linux.org>
PLD Linux Distribution




More information about the pld-devel-en mailing list