Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #12295

Re: Command substitution starting with a (()) expression should fail

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: Command substitution starting with a (()) expression should fail
Date 2016-01-31 19:51 -0500
Organization ITS, Case Western Reserve University
Message-ID <mailman.3286.1454287890.843.bug-bash@gnu.org> (permalink)
References <CA+M2tpFhbTYZkWtfWdN74NyODC5Puee62Va9O0Sj=wGbbRYsVg@mail.gmail.com>

Show all headers | View raw


On 1/31/16 7:26 PM, Michael Diamond wrote:

> Bash Version: 4.3
> Patch Level: 39
> Release Status: release
> 
> Description:
> I'm told $((( $exit_code == 0 )) && echo GREEN || echo RED) should fail
> to parse, because $(( should be the first token, not $(.

The way I read Posix, the bash behavior is allowed:

"The syntax of the shell command language has an ambiguity for expansions
beginning with "$((", which can introduce an arithmetic expansion or a
command substitution that starts with a subshell. Arithmetic expansion has
precedence; that is, the shell shall first determine whether it can parse
the expansion as an arithmetic expansion and shall only parse the
expansion as a command substitution if it determines that it cannot parse
the expansion as an arithmetic expansion."

One of the criteria bash uses to determine whether it's a valid arithmetic
expression is whether or not the parentheses are balanced.

It's basically up to the application to remove the ambiguity.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Command substitution starting with a (()) expression should fail Chet Ramey <chet.ramey@case.edu> - 2016-01-31 19:51 -0500

csiph-web