Crap, looks like I accidentally just replied to a single person instead of the whole list. Here it is (and sorry if I'm uselessly cluttering up everyone's inboxes!):
---------- Forwarded message --------- From: Great Big Dot <greatbig...@gmail.com> Date: Tue, Nov 6, 2018 at 5:45 PM Subject: Re: Indices of array variables are sometimes considered unset (or just display an error). To: <dual...@gmail.com> > On Mon, Nov 5, 2018 at 10:38 PM Eduardo Bustamante <dual...@gmail.com> wrote: > Sorry, I'm having a hard time following this email thread. My bad, sorry if I wasn't clear enough. I expected this: $ array=(foo) $ printf '%s\n' "${!array[@]-unset}" 0 That is, I expected the keys of 'array' to be printed, unless the array was unset. Instead, I either got errors or the "unset" string, and never the actual keys. I didn't even realize that the indirection had something to do with it, though once it hit me it made the behavior much clearer. I implicitly assumed that the indirection stuff only applied to non-array variables, and index-expansion only to array variables. > What is your ultimate goal or the actual problem you're trying to solve? Honestly, I was just messing around at the command line to get the hang of some of the expansions. IIRC, I was looking at the "parameter transformation" stuff ("${var@Q}", "${var@A}", etc.). I was looking for any edge cases that might trip me up in the future, and eventually I wondered what would happen if you used an array. Somehow that led to me trying other expansions with arrays, and I ended up getting errors I couldn't explain. > (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) Yeah, I think I'm starting to get that now...