[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
associative arrays and [[ -v
From: |
isabella parakiss |
Subject: |
associative arrays and [[ -v |
Date: |
Fri, 17 Apr 2015 11:12:50 +0200 |
I need to check if an element in an associative array is set. What's the
correct way to test it?
$ declare -A arr=([x]=y); var=*
$ [[ -v arr["$var"] ]]; echo $?
0
$ [[ ${arr["$var"]} ]]; echo $?
1
The former seems wrong, the glob is expanded even if "$var" is quoted.
The latter works but it doesn't distinguish between unset and empty.
Is there a way to test it with ''[[ -v'' ?
Also this one seems wrong, found by geirha:
$ declare -A a=([x]=y); [[ -v a ]]; echo $?
1
$ declare -A a=(["0"]=y); [[ -v a ]]; echo $?
0
---
xoxo iza
- associative arrays and [[ -v,
isabella parakiss <=