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


Groups > gnu.bash.bug > #14612

assoc_expand_once issues

From Grisha Levit <grishalevit@gmail.com>
Newsgroups gnu.bash.bug
Subject assoc_expand_once issues
Date 2018-09-20 18:37 -0400
Message-ID <mailman.1043.1537483093.1284.bug-bash@gnu.org> (permalink)

Show all headers | View raw


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

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web