help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Awkward behavior of empty arrays


From: Cristian Zoicas
Subject: Re: [Help-bash] Awkward behavior of empty arrays
Date: Thu, 7 Sep 2017 14:32:12 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:43.0) Gecko/20100101 Firefox/43.0 SeaMonkey/2.40



Greg Wooledge wrote:
On Thu, Sep 07, 2017 at 11:31:01AM +0200, Cristian Zoicas wrote:
Hm, interesting.  I think your whole message below can be rephrased as: empty 
arrays don't work with set -u.  Is that right?

right...

You know, I'd been taking this assertion on faith, but after testing
it, I just don't see any evidence that it's true.

wooledg:~$ set -u
wooledg:~$ unset a
wooledg:~$ for i in "address@hidden"; do :; done
wooledg:~$ a=()
wooledg:~$ for i in "address@hidden"; do :; done
wooledg:~$ a="a string"
wooledg:~$ for i in "address@hidden"; do :; done
wooledg:~$ unset a
wooledg:~$ a=([1]=foo)
wooledg:~$ for i in "address@hidden"; do :; done
wooledg:~$ echo "${a[0]}"
bash: a[0]: unbound variable
wooledg:~$ set +u

The ONLY way I can get -u to trigger is to reference a specific index
that is not set within the array.  In all other cases, an array that
is either unset or empty, or which has an index gap, works just
fine with "address@hidden" under -u.

Of course, -u is still horrible and I will never use it my scripts.
But it's not because of how it treats arrays.


Could you explain why -u is horrible? Does it have some drawback?

thx
Cristi



reply via email to

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