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

Re: [PATCH] Use == in expressions instead of the deprecated =



2016-09-08 12:16:28 +0100, Peter Stephenson:
[...]
> diff --git a/Doc/Zsh/cond.yo b/Doc/Zsh/cond.yo
> index 3d369fb..6fcf3bd 100644
> --- a/Doc/Zsh/cond.yo
> +++ b/Doc/Zsh/cond.yo
> @@ -103,8 +103,8 @@ true if var(file1) and var(file2) exist and refer to the same file.
>  xitem(var(string) tt(=) var(pattern))
>  item(var(string) tt(==) var(pattern))(
>  true if var(string) matches var(pattern).
> -The `tt(==)' form is the preferred one.  The `tt(=)' form is for
> -backward compatibility and should be considered obsolete.
> +The `tt(==)' form is the preferred one for clarity in new shell code
> +as it more closely resembles other languages.
[...]

ksh93 also makes "==" obsolete in [[...]]. "==" is still not
POSIX (and likely not going to be soon as requests to add it
have been rejected (IIRC)) for the "test"/"[" utility (or expr).

I suspect the reason David Korn obsoleted "==" is mainly for
consistency with the ((...)) "==" operator. There, "==" is
comparison and "=" is assignment like in C/awk (and other
languages that don't do the disambiguation via some other mean
like :=/= or <-/=).

However inside [[...]], there is no possible confusion between
assignment and comparison as [[...]] is only a construct for
doing tests, so no point in having a "==" there.

I personally use "=" (even for [[...]]), as that's what's
standard for "test"/"[".

The risk with stating that "==" is obsolete is that people are
going to start using [ "$a" == "$b" ] (as many do already)
thinking it's the right thing to do and get bitten when "sh"
changes from bash/zsh/ksh/yash to another sh implementation
whose "test" builtin doesn't support "=="

-- 
Stephane



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