dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG] quoted substring parameter expansion ignores single-quotes in the arg
@ 2017-09-26  3:41 G.raud
  2017-10-19 10:41 ` [NO-BUG] " G.raud
  0 siblings, 1 reply; 4+ messages in thread
From: G.raud @ 2017-09-26  3:41 UTC (permalink / raw)
  To: dash

To test that the single quotes are considered ordinary chars when
double-quoting the parameter expansion:

$ dash -c "a=\\'a\\'; echo \"\${a%'}\""

The result is surprising and non consistent with a non double-quoted
expansion where the single-quotes act as quotes:

$ dash -c "a=a%; echo \${a%'%'}"

Additionally the manual states that the arg to substring processing is
processed as an ordinary word (as probably POSIX too).

Regards

-- 
G.raud Meyer
graud@gmx.com

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

* Re: [NO-BUG] quoted substring parameter expansion ignores single-quotes in the arg
  2017-09-26  3:41 [BUG] quoted substring parameter expansion ignores single-quotes in the arg G.raud
@ 2017-10-19 10:41 ` G.raud
  2017-10-21 12:13   ` [BUG] " Jilles Tjoelker
  0 siblings, 1 reply; 4+ messages in thread
From: G.raud @ 2017-10-19 10:41 UTC (permalink / raw)
  To: dash

Wrong bug report.

In fact the beahviour of dash on "a=\\'a\\'; echo \"\${a%'}\"" is that
of POSIX and of zsh 5.  However 'bash --posix', 'mksh -o posix' and
pdksh fail to parse the command and ksh does not remove the quote from
$a.

On Tue, Sep 26, 2017 at 05:41:48AM +0200, G.raud wrote:
> Subject: [BUG] quoted substring parameter expansion ignores single-quotes
>  in the arg
> 
> To test that the single quotes are considered ordinary chars when
> double-quoting the parameter expansion:
> 
> $ dash -c "a=\\'a\\'; echo \"\${a%'}\""
> 
> The result is surprising and non consistent with a non double-quoted
> expansion where the single-quotes act as quotes:
> 
> $ dash -c "a=a%; echo \${a%'%'}"
> 
> Additionally the manual states that the arg to substring processing is
> processed as an ordinary word (as probably POSIX too).

-- 
G.raud Meyer
graud@gmx.com

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

* Re: [BUG] quoted substring parameter expansion ignores single-quotes in the arg
  2017-10-19 10:41 ` [NO-BUG] " G.raud
@ 2017-10-21 12:13   ` Jilles Tjoelker
  2017-10-25 10:08     ` Martijn Dekker
  0 siblings, 1 reply; 4+ messages in thread
From: Jilles Tjoelker @ 2017-10-21 12:13 UTC (permalink / raw)
  To: G.raud; +Cc: dash

On Thu, Oct 19, 2017 at 12:41:30PM +0200, G.raud wrote:
> Wrong bug report.

> In fact the beahviour of dash on "a=\\'a\\'; echo \"\${a%'}\"" is that
> of POSIX and of zsh 5.  However 'bash --posix', 'mksh -o posix' and
> pdksh fail to parse the command and ksh does not remove the quote from
> $a.

I think your original bug report is actually valid. Although the POSIX
standard may be hard to interpret (make sure to use the latest (2016)
edition), I think it is sufficiently clear that various special
characters are active in ${param#word}, whether the outer substitution
is within double-quotes or not. See this sentence in 2.6.2 Parameter
Expansion:

] Enclosing the full parameter expansion string in double-quotes shall
] not cause the following four varieties of pattern characters to be
] quoted, whereas quoting characters within the braces shall have this
] effect.

More generally, if bash --posix and ksh93 agree about something, it is
usually correct (use something like "${a#'*'}", since "${a#'}" is
wrong). Although zsh is a good interactive shell, it does not follow
POSIX as closely; not even in sh or ksh emulation mode.

Also note that dash does implement this correctly if a metacharacter is
quoted using a single-quote or a backslash:

$ v=**
$ echo "${v#*}"
**
$ echo "${v#"*"}"
*
$ echo "${v#\*}"
*

In dash's internals, this bug is caused by not distinguishing between
+/-/=/? and #/##/%/%% varieties in the parser. Not maintaining state for
eacg nesting level makes the parser more elegant, but it is untenable
since there is no way one can parse both "${v+'}" and "${v#'*'}"
correctly without it.

-- 
Jilles Tjoelker

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

* Re: [BUG] quoted substring parameter expansion ignores single-quotes in the arg
  2017-10-21 12:13   ` [BUG] " Jilles Tjoelker
@ 2017-10-25 10:08     ` Martijn Dekker
  0 siblings, 0 replies; 4+ messages in thread
From: Martijn Dekker @ 2017-10-25 10:08 UTC (permalink / raw)
  To: dash

Op 21-10-17 om 14:13 schreef Jilles Tjoelker:
[...]
> I think it is sufficiently clear that various special
> characters are active in ${param#word}, whether the outer substitution
> is within double-quotes or not.

Yes -- this came up on austin-group-l some time ago as well.
https://www.mail-archive.com/austin-group-l@opengroup.org/msg00197.html

> Although zsh is a good interactive shell, it does not follow
> POSIX as closely; not even in sh or ksh emulation mode.

I think that may have changed. Try the latest version. Over the last
year or two, many POSIX compliance bugs have been fixed. I believe the
latest version is about as compliant as bash or dash.

Zsh does still accept the wrong "${param#'}" expansion like dash does,
but handling non-compliant input is more like an extension than actual
non-compliance. Zsh acts correctly on "${param#\'}", like dash. It also
acts correctly on "${param#'foo'}", *unlike* dash.

- M.

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

end of thread, other threads:[~2017-10-25 10:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-26  3:41 [BUG] quoted substring parameter expansion ignores single-quotes in the arg G.raud
2017-10-19 10:41 ` [NO-BUG] " G.raud
2017-10-21 12:13   ` [BUG] " Jilles Tjoelker
2017-10-25 10:08     ` Martijn Dekker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).