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

2015-02-21 Thread Chet Ramey
On 2/20/15 3:52 PM, Dan Douglas wrote: > IMO bash is exactly correct. I don't know how this could be "fixed" in > a way that would satisfy people without changing something very > fundamental. If you disable the initial expansion to `(())', then > `(($x))' wouldn't work (because arithmetic evaluat

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

2015-02-20 Thread Dan Douglas
On Thu, Feb 19, 2015 at 7:47 PM, Chet Ramey wrote: > On 2/18/15 4:14 PM, emanuelczi...@cryptolab.net wrote: >> tl;dr: thanks! no reply needed; >> >> Thanks guys. I had a hard time accepting that this is how it's supposed to >> work. >> I accepted it now. :) > > Yeah. The expression between (( and

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

2015-02-19 Thread Chet Ramey
On 2/18/15 4:14 PM, emanuelczi...@cryptolab.net wrote: > tl;dr: thanks! no reply needed; > > Thanks guys. I had a hard time accepting that this is how it's supposed to > work. > I accepted it now. :) Yeah. The expression between (( and )) is word expanded, since (( ... )) is supposed to be exact

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

2015-02-19 Thread Chet Ramey
On 2/18/15 7:57 PM, Eduardo A. Bustamante López wrote: > On Wed, Feb 18, 2015 at 10:14:10PM +0100, emanuelczi...@cryptolab.net wrote: >> That segfault though: > > I confirm that the segmentation fault is in the latest devel version. Here's the patch I applied, very similar to yours. Chet -- ``

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

2015-02-18 Thread Eduardo A . Bustamante López
> On 2/18/15 3:49 PM, Maarten Billemont wrote: [...] > > I think the more important question isn't "why does (( behave this way?", > > but rather "should (( behave this way?". > > > > It's probably not reasonable to expect the author to know and take into > > account that (( arr[$key] )) treats ke

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

2015-02-18 Thread Dan Douglas
it occurs when an associative array with an empty subscript is modified. $ ( typeset -A a; x='a[$()]++'; ((x)); ) -bash: a: bad array subscript -bash: a[$()]: bad array subscript Segmentation fault (core dumped) I could live without the error on an empty key to begin with. It can be hard to prote

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

2015-02-18 Thread Eduardo A . Bustamante López
On Wed, Feb 18, 2015 at 10:14:10PM +0100, emanuelczi...@cryptolab.net wrote: > That segfault though: I confirm that the segmentation fault is in the latest devel version. dualbus@dualbus ~ % gdb GNU gdb (GDB) 7.4.1-debian Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL v

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

2015-02-18 Thread emanuelczirai
tl;dr: thanks! no reply needed; Thanks guys. I had a hard time accepting that this is how it's supposed to work. I accepted it now. :) I just hope nobody is going to try to exploit it or something. That segfault though: set -x declare -A ar key='`echo -n "1">>times.txt`' ((++ar[$key])) # cmd i

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

2015-02-18 Thread Chet Ramey
On 2/18/15 3:49 PM, Maarten Billemont wrote: > > also this variant does the same: > > $ (('ar[$idbad2]+=11')) > > > Because (( and let are essentially equivalent. > > > I think the more important question isn't "why does (( behave this way?", > but rather "should (( behave this way

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

2015-02-18 Thread Maarten Billemont
> > > also this variant does the same: > > $ (('ar[$idbad2]+=11')) > Because (( and let are essentially equivalent. I think the more important question isn't "why does (( behave this way?", but rather "should (( behave this way?". It's probably not reasonable to expect the author to know and t

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

2015-02-18 Thread Chet Ramey
On 2/16/15 12:23 PM, emanuelczi...@cryptolab.net wrote: > 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 "a

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

2015-02-16 Thread emanuelczirai
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

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

2015-02-16 Thread Eduardo A . Bustamante López
On Mon, Feb 16, 2015 at 03:04:49AM +0100, emanuelczi...@cryptolab.net wrote: > Description: > when dealing with integer operations(let, ++), "bad array subscript" > errors > can happen because subscripts get unquoted (and evaluated even though they > are in single quotes); unlike what happen

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

2015-02-16 Thread Greg Wooledge
On Mon, Feb 16, 2015 at 03:04:49AM +0100, emanuelczi...@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 strin