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

Patterns in parameter substitution and quoting weirdness

It does not look like they behave very consistently in respect to quoting.

bor@itsrm2% typeset -A foo
bor@itsrm2% foo[ab]=ab_val
bor@itsrm2% foo[a\?]=a\?_val
bor@itsrm2% print ${(v)foo[(I)a?]}
ab_val <= where is `a?_val' ?? That looks like a plain bug
bor@itsrm2% print "${(v)foo[(I)a?]}"
ab_val <= so, `?' is not quoted by "..." ... but
bor@itsrm2% print ${(v)foo[(I)a\?]}
       <= ... it is quoted by \ or '...'
bor@itsrm2% print "${(v)foo[(I)a\?]}"
       <= I'd like very much to know, what's going on behind ...
bor@itsrm2% print "${(v)foo[(I)a\\?]}"
       <= I'd expect THIS to work - after all, zsh finally see '\?'
bor@itsrm2% print "${(v)foo[(I)a\\\?]}"
a?_val <= and here zsh actually gets '\\?' !

It looks, like string floats around with (de-)quoting applied here and there.

bor@itsrm2% bar='a?b'
bor@itsrm2% print ${bar/a?/ZZ}
ZZb <= that's O.K.
bor@itsrm2% print ${bar/a\?/ZZ}
ZZb <= sorry? While I can understand it, why it differs from the subscript?
bor@itsrm2% print "${bar/a?/ZZ}"
ZZb <= if the above is correct, this is correct as well
bor@itsrm2% print "${bar/a\?/ZZ}"
ZZb <= that is at least strange; see next; and again, why it differs from
bor@itsrm2% print "${bar/a\\?/ZZ}"
a?b <= WHAT!? zsh gets exatly the same string as above! (well, well, not
exactly ... but from the user's point of view it is very hard to explain).

As I see it, there are two possibilities:

- consistently apply Zsh quoting rules. That will make literal patterns inside
of double quotes impossible and force usage of temporary parameters.

- use own quoting. The only possibility looks like backslash. But then mention
it in manual at least! :-) And, in this case, it should not matter, if you use
$foo or $~foo for pattern - the result must be the same in both cases.


Have a nice DOS!
B >>

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