Re: unexpected parameter expansion

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

 



On Wed, May 19, 2010 at 07:19:28PM +0000, Gerrit Pape wrote:
> Hi, I get unexpected output with dash doing parameter expansions with }
> within quotes involved, e.g.

> $ dash -c 'foo=; echo ${foo:-"{a}bar"}'
> {abar}
> $ 

> I expected:
> {a}bar

Just for clarification, the open brace is inconsequential here. It does
not pair with a close brace (only ${ does). Certain versions of bash and
ksh implemented it that way, but it has since been corrected.

> http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02

When reading this, make sure to consider the recent discussion on the
Austin Group.

Except for single-quotes inside double-quoted #% substitutions, there
appears to be consensus about the change in note #399 in
http://austingroupbugs.net/view.php?id=221

This post of mine is particularly interesting for dash:
http://permalink.gmane.org/gmane.comp.standards.posix.austin.general/1924

> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=581428

That one does
  foo="${foo:-"{a}bar"}"
(note the extra double-quotes) which can only result in {abar}, an error
or an incomplete command with dash's approach. The inner quotes have no
effect whatsoever on dash's parser.c state and only generate
CTLQUOTEMARK bytes for expand.c. This is not so bad as these nested
double-quotes with +-=? substitutions result in unspecified behaviour,
and shells differ in what it means.

Dash is not the only shell that doesn't do what the parole people
expect. FreeBSD sh (pretty much all versions, including with my reworked
substitutions in 9-CURRENT, although I could change it fairly easily)
and the System V sh (from Heirloom Toolchest) also assign {abar} (but
accept it as a complete command).

I recommend splitting up the command. Although
  foo=${foo:-{a\}bar}
will work, some shells keep the backslash in
  foo="${foo:-{a\}bar}"
and some people are tempted to add double-quotes everywhere, even where
they are not needed and silent breakage would result.

> Sorry, I don't have a patch to suggest.

I think this part needs a testsuite before any further changes :)

You could start from the posh or FreeBSD sh testsuites and what's in the
commit messages. Or if you have little programmer time but lots of CPU
time, rebuild all packages in the debian archive :)

-- 
Jilles Tjoelker
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux