equal or double equal
am 13.10.2007 15:02:46 von tbinHi,
using = or == with string comparison is the same or not?
Thanks in advance to anyone answering.
-- Antonio
Hi,
using = or == with string comparison is the same or not?
Thanks in advance to anyone answering.
-- Antonio
Antonio Maschio wrote:
> Hi,
>
> using = or == with string comparison is the same or not?
>
> Thanks in advance to anyone answering.
>
> -- Antonio
Not. For more information, provide context.
Ed.
Antonio Maschio wrote:
> Hi,
>
> using = or == with string comparison is the same or not?
'==' is not supported by old shells.
According to Bolsky/Korn the programs test and [ accept '=',
while with the newer (non-POSIX) [[...]] operator
'=' is said to be obsolete and using '==' preferred.
In the context of the newer test operator [[...]] there's
nothing to indicate that '=' and '==' would be different
(in Kornshell at least).
Janis
>
> Thanks in advance to anyone answering.
>
> -- Antonio
On 2007-10-13, Antonio Maschio wrote:
>
> using = or == with string comparison is the same or not?
The single equals is standard, and accepted by all shells; the
double is not.
Awk uses the double equals for comparison.
--
Chris F.A. Johnson, author
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
2007-10-13, 10:58(-04), Chris F.A. Johnson:
> On 2007-10-13, Antonio Maschio wrote:
>>
>> using = or == with string comparison is the same or not?
>
> The single equals is standard, and accepted by all shells; the
> double is not.
[...]
In [ yes.
But not in $(( ... )) and (( ... )) or let (ksh, zsh, bash),
that is for arithmetic comparison.
[[, where implemented (ksh, zsh, bash) supports both and there's
no difference as far as I know. Note that inside [[ ... ]] is a
pattern matching operator, not a string comparison one (though
it can also be used for string comparison if you quote the right
hand side (the pattern)).
--
Stéphane