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: Rui Santos
Subject: Re: 4.2 error: processing command substitution within arithmetic operation
Date: Tue, 28 Jun 2011 11:15:01 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; pt-PT; rv:1.9.2.4) Gecko/20100608 SUSE/3.1.0 Thunderbird/3.1

 On 25-06-2011 01:50, Chet Ramey wrote:
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).
Hi Chet.  Thanks a lot for your help.
Just for the records, I've reverted my "pseudo" patch, applied yours and, tested it.
It solved the problem I've reported earlier.

Again Chet, thanks a lot for your help.

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

--
Regards,
Rui Santos




reply via email to

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