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


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

Re: Indices of array variables are sometimes considered unset (or just display an error).

Started byEduardo Bustamante <dualbus@gmail.com>
First post2018-11-05 19:37 -0800
Last post2018-11-05 19:37 -0800
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: Indices of array variables are sometimes considered unset (or just display an error). Eduardo Bustamante <dualbus@gmail.com> - 2018-11-05 19:37 -0800

#14768 — Re: Indices of array variables are sometimes considered unset (or just display an error).

FromEduardo Bustamante <dualbus@gmail.com>
Date2018-11-05 19:37 -0800
SubjectRe: Indices of array variables are sometimes considered unset (or just display an error).
Message-ID<mailman.3538.1541475485.1284.bug-bash@gnu.org>
On Mon, Nov 5, 2018 at 6:01 PM Great Big Dot <greatbigdot@gmail.com> wrote:
(...)
> > [... A]ccessing the index list of multiple-element arrays
> > fails when you append the unset expansion. With single-element
> > arrays, it fails iff the element in question contains any special
> > characters or whitespace, and thinks the array is unset otherwise.
> > (Further testing shows that a value of the empty string also throws
> > an error.) Finally, empty arrays are also considered unset[...]
>
> Oops, just realized what's causing this. I guess it isn't necessarily a
> bug? Debatable, I guess.
>
> What's actually happening here is that the *indirection* expansion
> "${!foo}", and not the *indices* expansion "${!foo[@]}", is what is being
> preformed on something like "${!array[@]-}". Both expansions, while
> unrelated, happen to use the same syntax, with the exception that
> indirections apply to normal variables and index expansions apply to array
> variables. For some reason, adding on the "${foo-default}" expansion causes
> the former to be used instead of the latter. This can be seen here:

Sorry, I'm having a hard time following this email thread.

What is your ultimate goal or the actual problem you're trying to solve?

(BTW, I would recommend against trying to do three expansions in one.
It might be more terse, but it's hard to read and as you found out,
leads to weird behavior)

[toc] | [standalone]


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


csiph-web