[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
test whether array variable is set with ${parameter:+word}
From: |
pphick |
Subject: |
test whether array variable is set with ${parameter:+word} |
Date: |
Thu, 16 Apr 2015 23:22:02 -0700 |
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/b/home/share/locale' -DPACKAGE='bash' -DSHELL
-DHAVE_CONFIG_H -I. -I. -I./include -I./lib -g -O2
uname output: Linux jupiter 2.6.43.8-1.fc15.i686.PAE #1 SMP Mon Jun 4 20:21:39
UTC 2012 i686 i686 i386 GNU/Linux
Machine Type: i686-pc-linux-gnu
Bash Version: 4.3
Patch Level: 0
Release Status: release
Description:
If the array variable does not contain an element at index 0 it tests as unset.
When the element at index 0 does exist, it tests as set.
Repeat-By:
declare -a X
X[1]=one
declare -p X
echo ${X:+defined}
X[0]=zero
declare -p X
echo ${X:+defined}
The first echo statement prints nothing; the second prints 'defined'.
The same thing happens with associative arrays: they test as unset, until the
key '0' is used. Presumable the same issue.
- test whether array variable is set with ${parameter:+word},
pphick <=