bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Array variables still seen by test -v as unset even after assignment


From: Pierre Gaston
Subject: Re: Array variables still seen by test -v as unset even after assignment
Date: Wed, 27 Jul 2016 09:06:50 +0300



On Tue, Jul 26, 2016 at 8:29 PM, <dtr@home.homenet> wrote:
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: x86_64-pc-linux-gnu-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I. -I./include -I. -I./include -I./lib  -DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' -DSTANDARD_UTILS_PATH='/bin:/usr/bin:/sbin:/usr/sbin' -DSYS_BASHRC='/etc/bash/bashrc' -DSYS_BASH_LOGOUT='/etc/bash/bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS -DSSH_SOURCE_BASHRC -march=corei7-avx -O2 -pipe -fomit-frame-pointer
uname output: Linux home 4.0.5-gentoo-i5 #11 SMP PREEMPT Thu Dec 31 00:13:56 MSK 2015 x86_64 Intel(R) Core(TM) i5-2500K CPU @ 3.30GHz GenuineIntel GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.3
Patch Level: 39
Release Status: release

Description:
        Unlike usual variables, that have been assigned an empty value, arrays are treated by test -v as if they weren’t assigned anything.

Repeat-By:

        $ unset nothing; declare -p nothing; [ -v nothing ]; echo $?
        bash: declare: nothing: not found
        1

        $ unset var; var= ; declare -p var; [ -v var ]; echo $?
        declare -- var=""
        0

        $ unset arr; arr=(); declare -p arr; [ -v arr ]; echo $?
        declare -a arr='()'
        1

This has been reported and discussed several times.
bash consider an array as unset until at least one of its element has been assigned a value.

reply via email to

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