On Tue, Mar 03, 2015 at 01:55:55AM -0600, vampyre...@gmail.com wrote: > > imadev:~$ i="a'b" > > imadev:~$ unset 'foo[$i]' > > However, I did not try that way, because -- according to the bash > documentation -- it shouldn't work. Single quotes should prevent the > expansion of $i. Even knowing now that this does work, I can't find where > this exception to single-quote behavior is documented.
Think of it as a two-step process. The first step is ordinary expansion and quote removal. Since the $i is inside single quotes, it is not expanded. The quotes are removed, and we're left with foo[$i]. Then the array *itself* does a second expansion step, but it does so in a context where the expanded contents cannot possibly be treated as syntax. I don't think this is documented in the manual.