bug-bash
[Top][All Lists]
Advanced

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

Re: 4.2 error: processing command substitution within arithmetic operati


From: Chet Ramey
Subject: Re: 4.2 error: processing command substitution within arithmetic operation
Date: Fri, 24 Jun 2011 20:50:04 -0400
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10

On 6/24/11 1:18 PM, Rui Santos wrote:

> Try this script:
> #!/bin/bash
> 
> declare -ax array
> array[$(( $( echo -n 1001 ) - 1001 ))]=1
> 
> this will issue an error: line 6: 1001: command not found
> 
> If however the script is turned into:
> #!/bin/bash
> 
> declare -ax array
> array[$(( `echo -n 1001` - 1001 ))]=1
> 
> it works perfectly.
> 
> The first script will run without any problems on bash-4.1-9
> However if, on bash 4.2-10 (where the 1st script fails), you have a script
> like:
> #!/bin/bash
> echo $(( $( echo -n 1001 ) - 1001 ))
> 
> it also works fine.
> strange...

Yes.  It's a case of not saving and restoring enough state across possibly-
recursive calls to the shell parser.  (The assignment statement is the key
in this case.)

> So, I compared subst.c files from bash-4.1-9 and bash-4.2-10 and was able
> to build a patch that it seems to make it work.
> So to all you Bash guru's, can this patch be applied with no extra
> consequences ?

No.  The code is in there for a reason.  It's part of the fix for Posix
interpretation 217 (http://austingroupbugs.net/view.php?id=217).

The right fix is to save and restore the right shell context around
recursive calls to the parser.  The attached patch does that, and the
result passes the rest of the test suite (which obviously needs to be
augmented).

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/

Attachment: parser-state.diff
Description: Text document


reply via email to

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