Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: string equal problem
Frank Terbeck wrote:
> Lyre wrote:
>> To my surprise,the following statment:
>>
>> if [ "abc" == "def" ]; then echo y; else echo n; fi
>>
>> doesn't work, it says "zsh: = not found".
>
> `==' only works in "[[ ... ]]". [...]
Actually, that's not quite true.
`[' works like a command, thus == is seen like it is for any other
command too. And in those cases, the leading equal leads to expansion of
the corresponding program's full path. For example
zsh% print =emacs
/usr/bin/emacs
Now, there is no command "=" on your system, which is why you're getting
the correct message "= not found". To prevent this, you can either unset
the `EQUALS' option (man zshoptions | less -p EQUALS) or quote the
string that is otherwise subject to this expansion. As in:
if [ 'abc' '==' 'def' ]; then
Regards, Frank
--
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
-- RFC 1925
Messages sorted by:
Reverse Date,
Date,
Thread,
Author