[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Non-empty associative array considered not-set by -v test
From: |
林博仁 |
Subject: |
Non-empty associative array considered not-set by -v test |
Date: |
Sun, 28 May 2017 03:07:45 +0800 |
Hi, please consider the following script:
```
declare -ar indexed_array=(1 2 3)
declare -ar indexed_array_null=()
declare -Ar associative_array=(\
["apple"]="1" \
["banana"]="2" \
)
declare -Ar associative_array_null=()
for parameter in indexed_array indexed_array_null associative_array
associative_array_null; do
declare -n array_nameref="${parameter}"
if [ ! -v array_nameref ]; then
printf "%s is NOT set\n" "${parameter}"
else
printf "%s is set\n" "${parameter}"
fi
unset -n array_nameref
done
```
- Non-empty associative array considered not-set by -v test,
林博仁 <=