bug-bash
[Top][All Lists]
Advanced

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

assoc_expand_once issues


From: Grisha Levit
Subject: assoc_expand_once issues
Date: Thu, 20 Sep 2018 18:37:57 -0400

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


reply via email to

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