From owner-freebsd-questions Thu Apr 6 15:33: 6 2000 Delivered-To: freebsd-questions@freebsd.org Received: from news-ma.rhein-neckar.de (news-ma.rhein-neckar.de [193.197.90.3]) by hub.freebsd.org (Postfix) with ESMTP id 8C12537B515 for ; Thu, 6 Apr 2000 15:32:59 -0700 (PDT) (envelope-from daemon@bigeye.rhein-neckar.de) Received: from bigeye.rhein-neckar.de (uucp@localhost) by news-ma.rhein-neckar.de (8.8.8/8.8.8) with bsmtp id AAA01806 for freebsd-questions@freebsd.org; Fri, 7 Apr 2000 00:32:58 +0200 (CEST) (envelope-from daemon@bigeye.rhein-neckar.de) Received: (from daemon@localhost) by bigeye.rhein-neckar.de (8.9.3/8.9.3) id XAA49510 for freebsd-questions@freebsd.org; Thu, 6 Apr 2000 23:46:21 +0200 (CEST) (envelope-from daemon) From: naddy@mips.rhein-neckar.de (Christian Weisgerber) Subject: Re: Comparing Floats in a /bin/sh Script Date: 6 Apr 2000 23:46:20 +0200 Message-ID: <8cj0jc$1gar$1@bigeye.rhein-neckar.de> References: <20000406120827.A4198@cc942873-a.ewndsr1.nj.home.com> To: freebsd-questions@freebsd.org Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Crist J. Clark 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