On Fri, Jun 24, 2011 at 06:18:08PM +0100, 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

imadev:~$ unset array
imadev:~$ array[$(( $( echo -n 1001 ) - 1001 ))]=1
imadev:~$ unset array
bash: 1001: command not found

And similar... hmm, this is beyond weird.  I have no idea what's happening
here.

But if you want to work around the problem, I would suggest simplifying
things.  For starters, you do not need $((...)) inside an array index
because the [...] already introduce a math context.

So:

imadev:~$ array[$(echo -n 1001) - 1001]=1
imadev:~$ set | grep array=
array=([0]="1")
imadev:~$ unset array

And that assumes you need to keep the command substitution for some
unstated reason.  If you can get rid of that too, that would be even
better.

Reply via email to