Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: unset "hash[key]" isn't matched with what "key" may be



On Feb 9,  8:53am, Peter Stephenson wrote:
} Subject: Re: unset "hash[key]" isn't matched with what "key" may be
}
} All that occurred to me was an additional option to provoke an extra
} expansion step on the argument after locating the brackets.
} 
}   unset -? 'hash[$i]'
} 
} would then be reliable.  If the extra backslash stripping occurred early
} enough it wouldn't get in the way.

So what magic makes this work for typeset?

torch% typeset -A foo
torch% x='['
torch% typeset "foo[$x]"     
zsh: not an identifier: foo[[]
torch% typeset 'foo[$x]'		<-- note here
torch% typeset -p foo
typeset -A foo=( '[' '' )
torch% 

Or perhaps an equally interesting question is, is that behavior in fact
incorrect and typeset shouldn't do it either?

Ksh:

$ x='['
$ typeset -A foo
$ typeset "foo[$x]"
ksh: typeset: foo[[]: invalid variable name
$ typeset foo[$x]				<-- not an error?
$ typeset -p foo
typeset -A foo=(['[]']=)			<-- but weird
$ typeset 'foo[$x]'
$ typeset -p foo
typeset -A foo=(['$x']= ['[]']=)		<-- no expansion
$ 




Messages sorted by: Reverse Date, Date, Thread, Author