bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gawk bug - 'is equal' is faulty for string


From: Davide Brini
Subject: Re: gawk bug - 'is equal' is faulty for string
Date: Mon, 27 Jan 2020 15:36:47 +0100

On Mon, 27 Jan 2020 14:28:55 +0100, Jérôme Jargot <address@hidden>
wrote:

> Hello,
> 
> This is not the last gawk version and I think I must be mistaken because
> the == is very likely not buggy for strings.
> Still I do not understand my mistake, so I submit a bug report.
> 
> *TESTS: 'is equal' is faulty for string => 2 lines printed instead of 1*
> 
> # printf "'a', '7.1'\n'a', '7.2'\n'a', '7.3'\n'a', '7.10'\n" "" | LC_ALL=C
> gawk --field-separator \' '$4==cversion {print}' cversion=7.10
> 'a', '7.1'
> 'a', '7.10'
> 
> # printf "'a', '7.1'\n'a', '7.2'\n'a', '7.3'\n'a', '7.10'\n" "" | LC_ALL=C
> gawk --field-separator \' '$4==cversion {print}' cversion=7.1
> 'a', '7.1'
> 'a', '7.10'

If something looks like a number, awk may choose to interpret it as string
or number, depending on the context (see this page for more information:
https://www.gnu.org/software/gawk/manual/gawk.html#Variable-Typing). If you
want to force string comparison, you have to use somethig like:

gawk --field-separator \' '$4""==cversion"" {print}' cversion=7.10

that is, concatenate with the empty string to force string interpretation.

-- 
D.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]