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.

Reply via email to