[Top][All Lists]

[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 #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


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.


declare -a X

declare -p X
echo ${X:+defined}

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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]