Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14612 > unrolled thread

assoc_expand_once issues

Started byGrisha Levit <grishalevit@gmail.com>
First post2018-09-20 18:37 -0400
Last post2018-09-20 18:37 -0400
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug


Contents

  assoc_expand_once issues Grisha Levit <grishalevit@gmail.com> - 2018-09-20 18:37 -0400

#14612 — assoc_expand_once issues

FromGrisha Levit <grishalevit@gmail.com>
Date2018-09-20 18:37 -0400
Subjectassoc_expand_once issues
Message-ID<mailman.1043.1537483093.1284.bug-bash@gnu.org>
I was testing out this new feature and I can't figure out how to handle
certain characters in subscripts when the option is on.  Without the
option,
it is possible to escape the `$' in the subscript to achieve the desired
result but obviously that does not work if the option *is* on -- is there a
different workaround to use or is this a bug with assoc_expand_once?

Specifically, the following characters prove to cause an issue:

shopt -s assoc_expand_once
declare -A A

for k in $'\t' ' '; do
   (( A[$k]=2 ))
   declare -p A
done
# declare -A A=()
# declare -A A=()

for k in ']' '*' '@'; do
   (( A[$k]=2 ))
done
# -bash: ((: A[]]=2: syntax error: invalid arithmetic operator (error token
is "]=2")
# -bash: A[*]: bad array subscript
# -bash: A[@]: bad array subscript

for k in $'\t' ' ' ']' '*' '@'; do
   read "A[$k]" <<< X
   # or printf -v "A[$k]" X
done
# -bash: read: `A[ ]': not a valid identifier
# -bash: read: `A[ ]': not a valid identifier
# -bash: read: `A[]]': not a valid identifier
# -bash: A[*]: bad array subscript
# -bash: A[@]: bad array subscript

for k in ']' '*' '@'; do
   declare A[$k]=X
done
# -bash: declare: `A[]]=X': not a valid identifier
# -bash: A[*]: bad array subscript
# -bash: A[@]: bad array subscript

for k in $'\t' ' ' ']'; do
   unset "A[$k]"
done
# -bash: unset: `A[ ]': not a valid identifier
# -bash: unset: `A[ ]': not a valid identifier
# -bash: unset: `A[]]': not a valid identifier

for k in '*' '@'; do
   declare -A A; unset "A[$k]"; declare -p A
done
# -bash: declare: A: not found
# -bash: declare: A: not found

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web