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

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



[I see PWS has already responded while I was trying to work out what the
code is doing.  Here's what I've written so far, maybe I can come up with
a patch in a bit longer.]

On Feb 7,  3:16pm, Sebastian Gniazdowski wrote:
}
} I was testing following plugin:
} 
} https://github.com/hchbaw/opp.zsh

Which incidentally says (README.md) it is obsolete for zsh >= 5.0.8.

} It creates functions with sophisticated names, like
} 
} opp+a(                               opp+a)
} opp+a<                               opp+a>
} opp+a[                               opp+a]

Ooh, interesting.  Making use of the side-effect that you can give a
ZLE widget a function name that can't normally be typed unquoted on a
command line.  Kinky.

}                 unset "func[$i]"
} 
} yielded:
} 
} -zplg-diff-functions:unset:36: func[opp+a\[]: invalid parameter name

Yep, "unset" is pretty naive about parsing the subscript there.  It wants
the square brackets in balanced pairs and doesn't consider any kind of
quoting.  (The -m option also doesn't work for subscripts.)

For whatever it's worth, this doesn't work in ksh either (at least as of

$ print $KSH_VERSION
Version JM 93u 2011-02-08

) although the error isn't printed in the exact same circumstances; in
some cases it just silently fails:

$ y='['
$ ary=([$y]=1)
$ typeset -p ary
typeset -A ary=(['[']=1)
$ unset ary[$y]
$ typeset -p ary
typeset -A ary=(['[']=1)
$ ary[x]=1
$ typeset -p ary
typeset -A ary=(['[']=1 [x]=1)
$ unset ary[x]
$ typeset -p ary
typeset -A ary=(['[']=1)
$ unset "ary['[']"   
ksh: unset: ary['[']: invalid variable name
$ unset ary[\[]
$ typeset -p ary
typeset -A ary=(['[']=1)
$ 


-- 
Barton E. Schaefer



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