From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Fwd: command substitutions starting with $((
Date: Tue, 22 Dec 2009 14:02:28 -0800 [thread overview]
Message-ID: <6bb609560912221402i6bfd07b8ob3f1cb2d9af2a1cc@mail.gmail.com> (raw)
In-Reply-To: <20091222113413.GA9234@squonk.masqnet>
Tail of a fairly interesting thread on the austin-group (POSIX) list.
---------- Forwarded message ----------
From: Geoff Clare <gwc@opengroup.org>
Date: Tue, Dec 22, 2009 at 3:34 AM
Subject: Re: command substitutions starting with $((
To: austin-group-l@opengroup.org
Philip Guenther <guenther@gmail.com> wrote, on 21 Dec 2009:
>
> On Mon, Dec 21, 2009 at 9:53 AM, Geoff Clare <gwc@opengroup.org> wrote:
> ...
> > Are you claiming there are text sequences such that $((text)) is
> > syntactically valid both as an arithmetic substitution and as a
> > command substitution, and it is not a "single subshell" command
> > substitution?
> >
> > Unless such text sequences exist, it seems clear that the shell is
> > required to distinguish between the two cases based on which one the
> > syntax is valid for.
>
> How about:
>
> cat=1 ; EOH=3; echo $(( cat <<EOH
> + ( (
> EOH
> ) && ( cat <<EOH
> ) ) + 1 +
> EOH
> ))
<Applause> We have a winner. I'm impressed :-)
This means we do need to make a change to the standard. The tricky
part is going to be deciding exactly what to change.
Since it's a simple matter for application writers to use "$( ("
instead of "$((" when they are writing a command substitution
that starts with a subshell, I think it would be appropriate for
the standard to say that arithmetic expansion has precedence.
I.e. if $(( introduces a syntactically valid arithmetic expansion,
then an arithmetic expansion will be performed. Otherwise if $((
introduces a syntactically valid command substitution, then a
command substitution will be performed. If the syntax is valid
for neither, then it is unspecified what kind of syntax error the
shell reports. (Or a modification of this which retains the
"single subshell" rule.)
This appears to match what current shells do. All the shells I
tried Philip's example in output 256.
--
Geoff Clare <g.clare@opengroup.org>
The Open Group, Thames Tower, Station Road, Reading, RG1 1LX, England
parent reply other threads:[~2009-12-22 22:08 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20091222113413.GA9234@squonk.masqnet>]
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=6bb609560912221402i6bfd07b8ob3f1cb2d9af2a1cc@mail.gmail.com \
--to=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
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).