autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bash bug in $()


From: Eric Blake
Subject: bash bug in $()
Date: Wed, 28 Dec 2005 18:20:34 +0000

Dan Jacobson uncovered what I believe is a bash bug:
http://article.gmane.org/gmane.comp.shells.bash.bugs/8574

See my arguments as to why I think this is a violation of
POSIX rules:
http://article.gmane.org/gmane.comp.shells.bash.bugs/8575

Although the Shell Substitutions portion of the manual
already recommends using `foo` instead of $(foo),
it may be worth adding to that section to also document
that bash 3.0 (I haven't verified whether bash 3.1 has
fixed the bug), zsh (as of 4.2.6), and ksh (5.2.14) all
have a bug in parsing command substitutions with an
embedded case, when you don' t use a leading ( for
each pattern:

$ k=$(case x in x) echo hi ; esac)
bash: syntax error near unexpected token `esac'
$ k=`case x in x) echo hi ; esac`
$ echo $k
hi
$ k=$(case x in (x) echo bye ; esac)
$ echo $k
bye

For that matter, the following examples are required
in the POSIX rationale, but are misparsed by several
shells:

Required:
$ echo $(
> cat <</eof
> a here-doc with )
> eof
> )
a here-doc with )
$ echo $(
> echo abc # a comment with )
> )
abc
$

bash:
$ echo $(
> cat << /eof
> a here-doc with )
a here-doc with 
$ echo $(
> echo abc # a comment with )
> )
abc
)
$

--
Eric Blake




reply via email to

[Prev in Thread] Current Thread [Next in Thread]