From: Jilles Tjoelker <jilles@stack.nl>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Harald van Dijk <harald@gigawatt.nl>,
dash@vger.kernel.org, jrnieder@gmail.com
Subject: Re: [PATCH] [PARSER] Remove backslash before } in double-quotes in variable
Date: Fri, 11 Mar 2011 19:32:27 +0100 [thread overview]
Message-ID: <20110311183227.GA80688@stack.nl> (raw)
In-Reply-To: <20110310085927.GA10824@gondor.apana.org.au>
On Thu, Mar 10, 2011 at 04:59:27PM +0800, Herbert Xu wrote:
> On Sun, Nov 21, 2010 at 02:42:22PM +0100, Jilles Tjoelker wrote:
> > The backslash prevents the closing brace from terminating the
> > substitution, therefore it should be removed.
> >
> > FreeBSD sh test expansion/plus-minus2.0 starts working, no other tests
> > are affected.
> >
> > Example:
> > printf "%s\n" ${$+\}} ${$+"\}"} "${$+\}}"
> > should print } three times, without backslashes.
> I agree with respect to the last one, but not the middle one.
> ${$+"\}"} should be identical in behaviour to "\}", which with
> all shells I have access to produces a brace with a backslash.
> So please update your patch so that we do not regress on the
> second one.
Meh. Now that I read http://austingroupbugs.net/view.php?id=221#c399
again, that particular bit is not so clear anymore. :(
That change only seems to affect parameter expansions inside
double-quotes, not double-quotes inside parameter expansions.
On the other hand, removing the backslash makes some sense because
${$+"}"} is unspecified (even though it expands to } in many shells). In
dash in particular it has an undesirable effect. When I wrote the code
to remove the backslash in FreeBSD sh, the first } ended the
substitution which as a result ended double-quoted although it started
unquoted; I changed this later so that the first } is literal, but did
not change the treatment of \} in that case.
My patch for dash goes further than what I did in FreeBSD in that it
also affects the four varieties of parameter expansion for substring
processing (#/##/%/%%). I think that is wrong and the FreeBSD behaviour
is correct. In the standard as modified by the aforementioned
interpretation, ${v#"}"} and ${v#'}'} seem valid (the pattern is a
literal closing brace). Therefore there seems no reason to remove the
backslash in ${v#"\}"}, even though ksh93 does it.
Distinguishing #/##/%/%% from the others at parse time is not possible
with the way dash's parser.c currently works. So a simple patch would
attempt to change \} inside "${...}" only (test dqvarnest instead of
varnest). I think that does not affect the end result for #/##/%/%% so
perhaps it can be committed as an small improvement.
At some point a larger change is probably necessary to fix things like
"${v#'a'}" which should trim the letter a, not single-quote a
single-quote. This works in FreeBSD 9 sh but I think its
Bourne/Korn-like approach to POSIX-unspecified constructs like
"${v+"what*is*this"}", which generates pathnames, just like the original
ash and older FreeBSD code, may not be appreciated in dash.
Some examples:
FreeBSD 9 sh does this:
% sh
$ v='a\}b'
$ echo ${v%"\}"*}
a
$ echo ${v+"\}"}
}
while dash with my original patch and ksh93 do this:
% ksh93
$ v='a\}b'
$ echo ${v%"\}"*}
a\
$ echo ${v+"\}"}
}
--
Jilles Tjoelker
next prev parent reply other threads:[~2011-03-11 18:32 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-13 16:28 Quoted closing brace in variable default expansion Harald van Dijk
2010-11-13 16:41 ` Jonathan Nieder
2010-11-13 17:29 ` Harald van Dijk
2010-11-19 13:54 ` Herbert Xu
2010-11-20 0:43 ` Harald van Dijk
2010-11-20 20:57 ` Cristian Ionescu-Idbohrn
2010-11-21 13:42 ` [PATCH] [PARSER] Remove backslash before } in double-quotes in variable Jilles Tjoelker
2010-11-21 16:35 ` Jonathan Nieder
2010-11-23 18:46 ` Harald van Dijk
2011-03-10 8:59 ` Herbert Xu
2011-03-11 18:32 ` Jilles Tjoelker [this message]
2010-11-13 17:51 ` Quoted closing brace in variable default expansion Jilles Tjoelker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110311183227.GA80688@stack.nl \
--to=jilles@stack.nl \
--cc=dash@vger.kernel.org \
--cc=harald@gigawatt.nl \
--cc=herbert@gondor.apana.org.au \
--cc=jrnieder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.