[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Behaviour of test -v with assoc array and quote character in key
From: |
Daniel Gröber |
Subject: |
Behaviour of test -v with assoc array and quote character in key |
Date: |
Mon, 15 Feb 2021 00:27:42 +0100 |
User-agent: |
NeoMutt/20180716 |
Hi list,
I've found what I belive to be a bug in how `test -v` expands the key in an
associative array. The following minimal test case demonstrates the
problem:
declare -A array
mytest () {
array["$1"]=123
test -v array["$1"]
printf 'test -v array[%s]; $?=%s\n' "$1" "$?"
}
mytest 'a' # prints: test -v array[a]; $?=0
mytest '"' # prints: test -v array["]; $?=1
echo "keys: ${!array[*]}" # prints: keys: " a
With a regular alphanumeric key `test -v` will return zero, indicating the
array element exists. However if we specify a variable that expands to
something containing the double quote character the test doesn't succeeed
indicating the key doesn't exist though it does as we can observe by the
expansion of ${!array[*]}.
Do you think this intended behaviour or a real bug?
Tested on Debian buster, with bash_5.0-4 ($BASH_VERSION="5.0.3(1)-release")
and git master commit 76404c85d492c001f59f2644074333ffb7608532.
Thanks,
Daniel
PS: Please keep me in CC as I'm not subscribed.
- Behaviour of test -v with assoc array and quote character in key,
Daniel Gröber <=