no idea about your internal rules of keyword and builtin but clearly its gotta parse it at most 1. level otherwise its big security fault isnt it its a shell fuctionality keyword, unset, so ..
On Tue, Mar 16, 2021 at 1:21 PM Greg Wooledge <g...@wooledge.org> wrote: > On Tue, Mar 16, 2021 at 09:24:01AM +0100, Alex fxmbsw7 Ratchev wrote: > > it doesnt make me much sense that unset -v assoc[$key] gives syntax error > > or so.. > > Think of it this way: what would happen if you had a filename in a > variable -- say, $file -- and you ran this command: > > rm -f $file > > You'd expect that to fail, right? Of course. > > unset -v assoc[$key] fails for exactly the same reason. unset does not > have any magical powers. It's only a shell builtin, NOT a shell keyword. > Therefore, the standard shell rules apply. Expansions occur first, > followed by word splitting, which cause a list of argument words to be > created and passed as arguments to the builtin. > > key='two words' > unset -v assoc[$key] > > ==> 'unset' '-v' 'assoc[two' 'words]' > > You can even use set -x to see this in action: > > unicorn:~$ key='two words' > unicorn:~$ set -x > unicorn:~$ unset -v assoc[$key] > + unset -v 'assoc[two' 'words]' > bash: unset: `assoc[two': not a valid identifier > bash: unset: `words]': not a valid identifier > >