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: Dan Douglas
Subject: Re: array subscripts act differently for integers(ie. let)
Date: Wed, 18 Feb 2015 19:44:39 -0600

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 protect against errors. Although bash doesn't throw
exceptions on referencing any undefined index like many languages, you
still have to guard against an empty key whenever its value isn't
known.

"${key+${a[$key]}}", or else "${a[${key}_]}" followed by
"${a[${key%_}]}" on each usage. Or at minimum [[ $key ]] on every
iteration of a loop over "${!a[@]}". It's almost uglier than `set -u'
workarounds...

-- 
Dan Douglas



reply via email to

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