All of lore.kernel.org
 help / color / mirror / Atom feed
* unexpected parameter expansion
@ 2010-05-19 19:19 Gerrit Pape
  2010-05-19 22:01 ` Jilles Tjoelker
  0 siblings, 1 reply; 3+ messages in thread
From: Gerrit Pape @ 2010-05-19 19:19 UTC (permalink / raw)
  To: dash

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

http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=581428

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

Thanks, Gerrit.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: unexpected parameter expansion
  2010-05-19 19:19 unexpected parameter expansion Gerrit Pape
@ 2010-05-19 22:01 ` Jilles Tjoelker
  2010-05-27 11:41   ` Herbert Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Jilles Tjoelker @ 2010-05-19 22:01 UTC (permalink / raw)
  To: dash

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: unexpected parameter expansion
  2010-05-19 22:01 ` Jilles Tjoelker
@ 2010-05-27 11:41   ` Herbert Xu
  0 siblings, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2010-05-27 11:41 UTC (permalink / raw)
  To: Jilles Tjoelker; +Cc: dash

On Wed, May 19, 2010 at 10:01:10PM +0000, Jilles Tjoelker wrote:
> 
> 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

Yeah I agree that dash should also be fixed here.  However, I've
run out of time today so this will have to wait until the next time
I look at dash.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-05-27 11:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-19 19:19 unexpected parameter expansion Gerrit Pape
2010-05-19 22:01 ` Jilles Tjoelker
2010-05-27 11:41   ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.