* Fwd: command substitutions starting with $((
[not found] ` <20091222113413.GA9234@squonk.masqnet>
@ 2009-12-22 22:02 ` Bart Schaefer
0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 2009-12-22 22:02 UTC (permalink / raw)
To: zsh-workers
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-12-22 22:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20091219211403.GA94709@stack.nl>
[not found] ` <20091221101508.GA1634@squonk.masqnet>
[not found] ` <4B2FB116.4070900@case.edu>
[not found] ` <20091221175312.GA16707@squonk.masqnet>
[not found] ` <dd0728a90912211132g1e891e8bm766f0cc083820d45@mail.gmail.com>
[not found] ` <20091222113413.GA9234@squonk.masqnet>
2009-12-22 22:02 ` Fwd: command substitutions starting with $(( Bart Schaefer
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).