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

Re: what is truth?



On Fri, Oct 9, 2015 at 8:24 PM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:

>
> test ()
> {
> [[ "$1" = <-> ]]  && echo true
> }
>
> I don't have a clue what to make of ' <-> '.  What value
> would work?
>

The redirection characters "<" and ">" are apparently still interpreted as
such even within a "[[ ]]" construct. Or something very similar is
occurring. Replace the dash with "x":

[[ '<->' = <x> ]] && echo true

You'll get the error "zsh: parse error: condition expected: '<->'". If you
quote the right-hand side of that expression you get the expected behavior
(with the original dash or the "x"). If you want to literally match "<->"
then put it inside single or double quote characters.

You need to understand that all UNIX shells, including zsh, have extremely
ad-hoc unexpected behaviors. This is a consequence of their input parsing
model coupled with dynamic options that configure them to behave more or
less like another shell. If you want more predictable and understandable
behavior you should be using languages like Python or Ruby.

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank


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