Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Eduardo Bustamante Newsgroups: gnu.bash.bug Subject: Re: Indices of array variables are sometimes considered unset (or just display an error). Date: Mon, 5 Nov 2018 19:37:48 -0800 Lines: 28 Approved: bug-bash@gnu.org Message-ID: References: <87va5bp5fr.fsf@gmail.com> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: usenet.stanford.edu 1541475486 17203 208.118.235.17 (6 Nov 2018 03:38:06 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash To: greatbigdot@gmail.com Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UkV0EAKq5vlvt+S/Mft+6qGonlF8Qsj1cH1Q8JG1Q00=; b=T35vuWTZpee+5FpoYqXDKoFdNHq5j8wJuwWIrHFyejL59z/TDgcKFVNDPdXV9+Ho1y XcpwB66HivbJV5zNNMMb9JYrqVuE9c4j8Wq2dUAjQC5vwBYamqVp4xSK3IRzFP0iTvtd sWxNEf1FB7pIn4RejPxPeYdj7+QPQzIHAbzxROSf1EgxLAf8YNxJ0VMl2qfJQgQbe6yd HfPiZBXTsnVCI24S8Zyj3+UUbzun3VqX4kgJ5ThcdJgNzFYBgBj2gpv8WTCfT8rN8gB/ C9eXY4cOOwITr1Abw5PUN4oq+LxarXVJGmPNApOHIy9jVK+mgW9P+yEL9qn3q55SyJPh grXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UkV0EAKq5vlvt+S/Mft+6qGonlF8Qsj1cH1Q8JG1Q00=; b=LMGrireEAt1R/BDmZTXy1I/U8x9J6MR+dgvfikQNdC8yGRBPuplGZ11GCb3qN4QwIa vSnBHEqyHDBoMtD1MOkDR/dFKNLRkjfHmiumYfZqlCC0jA/IoDZMpO8roxZkp7dcIrHI 5F+0/C9HyDLqGx3SF7us+xbU1nFv3BMa/D4RFvcGuq3Z5fBpr3hYkvvn6baNxDgx9BmQ Swtv/5DzGsBLRuI/RW2ybyQeBVk/rh0vfYErIhw7cv32tKGs/QzxU9tC6xaB59E4PDgU 8bQUfp6pabg7djv3d99emRg2Dev7ENP8MIKmQxzlApjU/eIcvbQpXg2lL13oPXix6j5O f2WQ== X-Gm-Message-State: AGRZ1gLPk60BE1QmFMQnoLs3NWAmW4mJdcuMqZixZA5pk/4w7z9NHg8s WHaX8I6uWAxkUJT5hr67eO0gqG9BflDnFMhkpmM= X-Google-Smtp-Source: AJdET5cSBnvD+jxzdDogmJ6sIQFpR3ABKWU0neqYP3V6nSFBeni/JLy1RrHtCQrPI8CeVaxCd0GHnsCVyBw1aDhPEWI= X-Received: by 2002:a19:d908:: with SMTP id q8mr13676785lfg.88.1541475481267; Mon, 05 Nov 2018 19:38:01 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::12c X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:14768 On Mon, Nov 5, 2018 at 6:01 PM Great Big Dot 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)