[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gawk bug - 'is equal' is faulty for string
From: |
Andrew J. Schorr |
Subject: |
Re: gawk bug - 'is equal' is faulty for string |
Date: |
Mon, 27 Jan 2020 09:42:08 -0500 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Mon, Jan 27, 2020 at 03:32:19PM +0100, Manuel Collado wrote:
> I think this is the expected result in both cases. The
> "$4==cversion" comparison is a numeric one, because both $4 and
> cversion values come from input data and look as numbers.
>
> Please search for "numeric string" or "strnum" in the gawk manual.
Manuel is correct. You can force a string comparison by concatenating one of
the operands with "", e.g. (y == x""). The chart below from the
docs is useful for understanding how comparison works. And in newer
versions of gawk, the typeof function is useful for getting a better
understanding of what's going on.
https://www.gnu.org/software/gawk/manual/html_node/Variable-Typing.html
When two operands are compared, either string comparison or numeric
comparison may be used. This depends upon the attributes of the
operands, according to the following symmetric matrix:
+----------------------------------------------
| STRING NUMERIC STRNUM
--------+----------------------------------------------
|
STRING | string string string
|
NUMERIC | string numeric numeric
|
STRNUM | string numeric numeric
--------+----------------------------------------------
Regards,
Andy