On 24-06-2011 21:01, Greg Wooledge wrote:
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.
Hi Greg. Thanks for your reply.
I was not aware of that. It will be remembered for future scripts. I do,
however, have legacy concerns to take care of and thus, I will need it
to work on this cases.
Thanks.
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.
--
Regards,
Rui Santos