bug-bash
[Top][All Lists]
Advanced

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

Re: array subscripts act differently for integers(ie. let)


From: emanuelczirai
Subject: Re: array subscripts act differently for integers(ie. let)
Date: Mon, 16 Feb 2015 18:23:53 +0100
User-agent: Roundcube Webmail

Oh I see, I had no idea that's how it's meant to work. My apologies.

However this case still doesn't work, but maybe I should use single quotes all the time?:

this fails(double quotes):
$ declare -A ar
$ idbad2="["
$ let "ar[$idbad2]+=11"
bash: let: ar[[]+=11: bad array subscript (error token is "ar[[]+=11")
$ declare -p ar
bash: declare: ar: not found

this works(single quotes):
$ let 'ar[$idbad2]+=11'
$ declare -p ar
declare -A ar='(["["]="11" )'


also this variant does the same:
fails:
$ (("ar[$idbad2]+=11"))
bash: ((: ar[[]+=11: bad array subscript (error token is "ar[[]+=11")
works:
$ (('ar[$idbad2]+=11'))
$ declare -p ar
declare -A ar='(["["]="22" )'

Thanks.

On 2015-02-16 17:56, Greg Wooledge wrote:
On Mon, Feb 16, 2015 at 03:04:49AM +0100, emanuelczirai@cryptolab.net wrote:
        please see attached bash script to reproduce because that explains
        it much better than I could in words.

The argument you give to let should be quoted.

imadev:~$ declare -A ar
imadev:~$ idbad1="bad string"
imadev:~$ let "ar[$idbad1]+=11"
imadev:~$ declare -p ar
declare -A ar='(["bad string"]="11" )'



reply via email to

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