bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Chet Ramey
Subject: Re: Command substitution starting with a (()) expression should fail
Date: Sun, 31 Jan 2016 19:51:22 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.5.0

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    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]