Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Fwd: command substitutions starting with $((
- X-seq: zsh-workers 27538
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Fwd: command substitutions starting with $((
- Date: Tue, 22 Dec 2009 14:02:28 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to :content-type:content-transfer-encoding; bh=doPnPiFOP9O/HG087YvGYxXqNU43LueFrgT0P9QUVOE=; b=xGLbKTtHy7CNb2FMH7Ygr6S1Gtwo21SfGe/KxEkybCzAitvCEQvhDGmddxrTl1adIZ EbI6CcjO9v99JRl+RBBF0wtJSUkifF4PBaU51xqZ42V+qVqIx/Rdc+sA5C7HSNaFFphT ieOxJiy+khwrfQYbj5KtYV/7ecx/lYcMNLt7s=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; b=gAqV6jCcWbI2Fpi/KoMJNbVF5S0HELRhLCm2qeBRsOgF9dEDFb8Eyk7Qt1gXOZWhcb PYRxZJiGFP1wmJtQU29HvG7AwrnDKpG+FzBParmfRTbUhD+snC2RPkABLFgSJ6mc0EGW +V/OJO2GC/cvsAGG+EycSjuEAs1ndymUbqlfY=
- In-reply-to: <20091222113413.GA9234@xxxxxxxxxxxxxx>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20091219211403.GA94709@xxxxxxxx> <20091221101508.GA1634@xxxxxxxxxxxxxx> <4B2FB116.4070900@xxxxxxxx> <20091221175312.GA16707@xxxxxxxxxxxxxx> <dd0728a90912211132g1e891e8bm766f0cc083820d45@xxxxxxxxxxxxxx> <20091222113413.GA9234@xxxxxxxxxxxxxx>
- Sender: barton.schaefer@xxxxxxxxx
Tail of a fairly interesting thread on the austin-group (POSIX) list.
---------- Forwarded message ----------
From: Geoff Clare <gwc@xxxxxxxxxxxxx>
Date: Tue, Dec 22, 2009 at 3:34 AM
Subject: Re: command substitutions starting with $((
To: austin-group-l@xxxxxxxxxxxxx
Philip Guenther <guenther@xxxxxxxxx> wrote, on 21 Dec 2009:
>
> On Mon, Dec 21, 2009 at 9:53 AM, Geoff Clare <gwc@xxxxxxxxxxxxx> 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@xxxxxxxxxxxxx>
The Open Group, Thames Tower, Station Road, Reading, RG1 1LX, England
Messages sorted by:
Reverse Date,
Date,
Thread,
Author