-------- Original-Nachricht --------
> I wouldn't expect that this would work, but I would expect that
>
> typeset -A foo=([']']="right brace")
> typeset input_char="]"
> typeset -n reference=foo[$input_char]
>
> or
>
> typeset -A foo=([']']="right brace")
> typeset input_char="]"
> typeset -n reference=foo[']']
>
> would work, but they don't and I will record this as a bug.
>
> A workaround until the bug is fixed is to use
>
> typeset input_char="\\]"
The problem is that input_char is external input I have no control over, I need
to sanitize it.
I tried this:
typeset -A foo=([']']="right brace")
typeset input_char="]"
typeset element=foo["$(printf "%q" "${input_char}")"]
typeset -n reference="${element}"
print "foo[']']=${reference}"
but it doesn't work either.
I could manually search and replace each occurrence of "]" with "\]", this here
works:
typeset -A foo=([']']="right brace")
typeset input_char="]"
input_char="${input_char//]/\\]}"
typeset element=foo["${input_char}"]
typeset -n reference="${element}"
print "foo[']']=${reference}"
Are there any other "special" characters which need to be taken care of?
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users