Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15716 > unrolled thread

Re: Two states of empty arrays

Started byClint Hepner <clint.hepner@gmail.com>
First post2019-12-12 14:06 -0500
Last post2019-12-12 14:06 -0500
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Two states of empty arrays Clint Hepner <clint.hepner@gmail.com> - 2019-12-12 14:06 -0500

#15716 — Re: Two states of empty arrays

FromClint Hepner <clint.hepner@gmail.com>
Date2019-12-12 14:06 -0500
SubjectRe: Two states of empty arrays
Message-ID<mailman.739.1576177562.1979.bug-bash@gnu.org>
On Thu, Dec 12, 2019 at 1:10 PM Léa Gris <lea.gris@noiraude.net> wrote:

> Hello,
>
> Depending on how an empty array is declared, it is not stored with the
> same state.
>
> # Empty array declared without parenthesis
> unset myArr
> declare -a myArr
> typeset -p myArr
> echo "${#myArr[@]}"
>
> output:
> declare -a myArr
> 0
>

Here, you haven't yet defined a parameter named myArr; you have only set
the array
attribute on the name myArr. You can see something similar with other
attributes:

$ declare -i x
$ [[ -v x ]] || echo "x not defined"
x not defined
$ declare -p x
declare -i x


>
> # Empty array declared without parenthesis
> unset myArr
> declare -a myArr=()
> typeset -p myArr
> echo "${#myArr[@]}"
>
> output:
> declare -a myArr=()
> 0
>
>
With the assignment, you have an actual parameter named myArr. Continuing
the integer attribute
example from above,

$ x=3
$ declare -p x
declare -i x="3"
$ [[ -v x ]] || echo "x not defined"   # No output


--
Clint

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web