#6 Validating Floating-Point Input

Upon first glance, the process of validating a floating-point (or "real") value within the confines and capabilities of a shell script might seem daunting, but consider that a floating-point number is only two integers separated by a decimal point. Couple that insight with the ability to reference a different script inline (validint), and you can see that the floating-point validation test is surprisingly short.

The Code

 #!/bin/sh # validfloat -- Tests whether a number is a valid floating-point value. # Note that this script cannot accept scientific (1.304e5) notation. # To test whether an entered value is a valid floating-point number, we # need to split the value at the decimal point. We then test the ...

Get Wicked Cool Shell Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.