Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Use of == in functions
- X-seq: zsh-users 24650
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Use of == in functions
- Date: Sun, 12 Jan 2020 12:03:53 +0000
- Archived-at: <http://permalink.gmane.org/gmane.comp.shells.zsh.devel/47201>
- In-reply-to: <20200112100906.GA95942__47727.4053309642$1578823915$gmane$org@pooh.prefix.duckdns.org>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mail-followup-to: zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <E24B3792-AAC1-4024-9B5C-708AC88769CE@gmail.com> <20200112100906.GA95942__47727.4053309642$1578823915$gmane$org@pooh.prefix.duckdns.org>
[repost to zsh-users. I'll see if I can add a mutt hook to avoid
the problem in the future].
2020-01-12 11:09:06 +0100, Kusalananda Kähäri:
[...]
> == within [[ ]]
> = within [ ]
>
> ... just like in bash (but bash allows its built in test/[ utility to
> understand == too)
[...]
zsh's [ builtin also supports == as an alias of = (like its [[
]] construct also supports == as an alias of =), but in zsh,
=cmd is an operator that expands to the path of the cmd command,
$ echo =ls
/usr/bin/ls
so you would need:
[ a '==' b ]
(or disable the =cmd feature with set +o equals) if for some
reason you wanted to use the non-standard == in place of =.
Just like you need
[ a '=~' regex ]
for regex matching.
And
[ a '<' b ]
to compare strings lexically as < is also a redirection
operator.
Now, as none of <, ==, =~ are standard [ operators (so sh
compatibility is no longer a good reason to use the "["
command), you might as well use the ksh-style [[...]] construct
which doesn't have this kind of issue:
[[ a =~ b ]], [[ a < b ]], [[ a == b ]] are all fine (but then
again, there's no need to double the =. == is an operator that
is needed in languages where there's a need to disambiguate
between assignment and equality comparison, but inside [[...]]
(as opposed to ((...)) for instance), there's no assignment)
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author