Date: 6 Apr 2000 23:46:20 +0200 From: naddy@mips.rhein-neckar.de (Christian Weisgerber) To: freebsd-questions@freebsd.org Subject: Re: Comparing Floats in a /bin/sh Script Message-ID: <8cj0jc$1gar$1@bigeye.rhein-neckar.de> References: <20000406120827.A4198@cc942873-a.ewndsr1.nj.home.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Crist J. Clark <cjclark@home.com> wrote: > I want to compare two floating point numbers in a /bin/sh script. I > cannot seem to find an easy way to do so. The best I've come up with > is, > > if awk "BEGIN { if ( $A < $B ) { exit 0 } else { exit 1 } }"; then ... > > There's got to be a better way? Hmm. if [ "$(echo "$A < $B" | bc)" -eq 1 ]; then ... Actually, that's worse. There is not shell built-in operator to handle floating point numbers. You need to use some external utility. awk(1) isn't a bad choice. -- Christian "naddy" Weisgerber naddy@mips.rhein-neckar.de To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8cj0jc$1gar$1>