This look like an XY problem.

If question look like:
 "How can I compare two floating point then fail
  when I encounter a pair where 1st are greater than
  2nd value... in bash"

Then answer seem not necessarily linked to `awk`!

Anyway, using awk, the method could be simplified:

  awk '{if ($1 > $2) exit 1}' <<<$'1.1 1.2\n1.3 1.4'

While `$1` stay no greater than `$2`, awk will continue,
then end with `success`... If one test fail, then
awk will exit with RC=1.

But the best is to know where you want to go...

Le Tue, Sep 09, 2025 at 12:10:55AM -0600, Stan Marsh a écrit :
> For the benefit of anyone trying to follow this thread, code in question 
> seems to be:
> 
> >if awk '{exit $1 < $2 ? 0 : 1;}' <<< '1.1 1.2' && awk '{exit $1 < $2 ? 0 : 
> >1;}' <<< '1.3 1.4'
> >then
> >  echo ok
> >fi
> 
> Actually, that is correct code - that actually works, although no one
> would ever do it like that - supplied by poster Oguz. We still have no
> idea what OP's original (wrong) code looked like.
> 
> I suppose that what this thread is really about is how some desperate
> shell coders resorted to AWK to do floating point comparisons before
> there was the fltexpr loadable command.
> 
> The underlying problem is that AWK's idea of true/false is the
> opposite of the shell's idea of success/fail. I.e., in AWK, 1 (or
> non-zero) = true, but if you exit with that, the shell interprets it
> as fail. So, you generally have to flip it for things to come out
> right. This inconsistency has caught me on a few occasions, but you
> get used to it (eventually).
> 
> In any case, I think the following does what OP wants in a more idiomatic way:
> 
> awk '{exit !($1 < $2 && $3 < $4) }' <<< '1.1 1.2 1.3 1.4' && echo OK
> 
> Or even:
> 
> awk '{exit $1 < $2 && $3 < $4 }' <<< '1.1 1.2 1.3 1.4' || echo OK
> 
> =================================================================================
> Please do not send me replies to my posts on the list.
> I always read the replies via the web archive, so CC'ing to me is unnecessary.
> 
> When responding to my posts, please try to refrain from giving bureaucratic 
> answers.
> If you have nothing useful to say, then just click Next and go on.
> 

-- 
 Félix Hauri  -  <[email protected]>  -  http://www.f-hauri.ch
__________________________________________________________________________
 Félix Hauri - Informaticien consultant  |\      /|       ___  _
 --------------------------------------  | \ __ / |      /    -   /   o
 4, rue Centrale / CH-1450 Sainte-Croix  | .    . |     /_  ___  /
 Tél: (+41/0) 24 454 54 04  Fax:..54 00  |   /\   |    /   /__/ /   /  \/
 http://www.f-hauri.ch                   | \ __ / |   /   /__  /_  /_  /\
 email: [email protected]                  \ ____ /   ---------------------
 Félix Hauri   -    Informaticien consultant    -   <[email protected]>
 Tél: (+41/0) 24 454 54 04 - 079 703 15 36   -   http://www.f-hauri.ch
##########################################################################  
 Ni PGP, ni cryptage:  Tant que mal maîtrisé et/ou mal installé ce sys-
 tème est entre inutile et dangereux. Attention! Il existe désormais des
 dispositions légales tendant à faire valoir à une signature électronique   
 le même poids qu'une signature manuscrite!
##########################################################################


Reply via email to