[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
test -v difference between bash 5.1 and 5.2
From: |
Christian Schneider |
Subject: |
test -v difference between bash 5.1 and 5.2 |
Date: |
Tue, 29 Aug 2023 16:32:36 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 |
Hi all,
not sure if this intended or not, but in bash 5.2-p15 one of our scripts
is broken. it is related to test -v, that checks, if a variable is set
together with arrays.
I condensed it to following example:
#!/bin/bash
declare -A foo
foo=(["a"]="b" ["c"]="d")
declare -a bar
bar=("a" "b" "c")
declare -a baz
baz=("foo" "bar")
for i in "${baz[@]}" ; do
echo $i
if [ ! -v "$i"[@] ] ; then
echo "$i not set"
fi
done
--------
with bash 5.2-p15 the output of this script is
foo
foo not set
bar
so, it doesn't work with associative arrays.
Instead, with 5.1-p16 the output is
foo
bar
so, in 5.1-p16 test -v with associative array works, but not with 5.2-p15.
I don't know, if this an intended change, so please can you take a look?
If it is intended, can you please explain, why this was changed, and if
there is an alternative for associative arrays?
BR, Christian
--
---------------------------------------------------------------------
RADIODATA GmbH
Newtonstr. 18
12489 Berlin
Germany
Homepage: www.radiodata.biz
USt_IdNr.: DE 195663499
WEEE-Reg.-Nr.: DE 63967380
Sitz der Gesellschaft: Berlin
Registergericht: Amtsgericht Charlottenburg HRB Nr.: 67865
Geschäftsführer: Hans-Joachim Langermann, Malte Langermann
- test -v difference between bash 5.1 and 5.2,
Christian Schneider <=
Re: test -v difference between bash 5.1 and 5.2, Kerin Millar, 2023/08/29