Sunday, May 18, 2025

bash Number Comparison is Confusing

A program rel compares two numbers and returns -1 0 or 1 depending on less than, equal, or greater than compare of the two floating point numbers.

I am trying to use the resulting exit code to make a decision.   -1 turns into 255 as $?.

What is the if statement to see if $? Is 1?

UPDATE: It is simpler to write a C program.   Fortunately bash is similar enough to C that I was able to copy and do some replaces to change it to C.  It should also be easier to debug.

I have changed my strategy.   I am going to write of these in C from now on.

My first job (and what I did most of the time I was there) was maintaining a 6000 line csh script that did automated testing of the LaserJet firmware.  If there is any stronger argument for limiting scripts to 200 lines. I cannot imagine it.

No comments:

Post a Comment