From owner-freebsd-questions@FreeBSD.ORG Thu Jun 24 17:09:28 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 10E611065673 for ; Thu, 24 Jun 2010 17:09:28 +0000 (UTC) (envelope-from carlj@peak.org) Received: from redcondor1.peak.org (redcondor1.peak.org [69.59.192.54]) by mx1.freebsd.org (Postfix) with ESMTP id DB77A8FC1C for ; Thu, 24 Jun 2010 17:09:27 +0000 (UTC) Received: from peak-mail-gateway.peak.org ([69.59.192.41]) by redcondor1.peak.org ({e03e86cd-14ae-47ce-9578-3c080ce9c462}) via TCP (outbound) with ESMTP id 20100624170927117 for ; Thu, 24 Jun 2010 17:09:27 +0000 X-RC-FROM: X-RC-RCPT: Received: from cjlinux.localnet (207.55.91.197.peak.org [207.55.91.197] (may be forged)) (authenticated bits=0) by peak-mail-gateway.peak.org (8.12.10/8.12.8) with ESMTP id o5OH9PLn071020 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Thu, 24 Jun 2010 10:09:25 -0700 (PDT) Received: from carlj by cjlinux.localnet with local (Exim 4.69) (envelope-from ) id 1ORpvZ-00031w-4j for freebsd-questions@freebsd.org; Thu, 24 Jun 2010 10:09:25 -0700 To: freebsd-questions@freebsd.org References: <4C22B3D7.6070102@comclark.com> <20100624033257.2D074BEA6@kev.msw.wpafb.af.mil> <87lja4mlme.fsf@cjlinux.localnet> From: Carl Johnson Date: Thu, 24 Jun 2010 10:09:25 -0700 In-Reply-To: <87lja4mlme.fsf@cjlinux.localnet> (Carl Johnson's message of "Thu\, 24 Jun 2010 09\:38\:33 -0700") Message-ID: <87hbksmk6y.fsf@cjlinux.localnet> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: .sh check for numeric content X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jun 2010 17:09:28 -0000 Carl Johnson writes: > vogelke+unix@pobox.com (Karl Vogel) writes: > >>>> On Thu, 24 Jun 2010 09:24:39 +0800, >>>> Aiza said: >> >> A> Receiving a variable from the command line that is suppose to contain >> A> numeric values. How do I code a test to verify the content is numeric? >> >> The script below will work with the Bourne or Korn shell. >> Results for "0 1 12 1234 .12 1.234 12.3 1a a1": >> >> 0 is numeric >> 1 is numeric >> 12 is numeric >> 1234 is numeric >> .12 is numeric >> 1.234 is numeric >> 12.3 is numeric >> 1a is NOT numeric >> a1 is NOT numeric > > You might want to try testing "123..45". > I tried changing: >> if expr "$arg" : "[0-9]*[\.0-9]*$" > /dev/null > to: > if expr "$arg" : "[0-9]*\.*[0-9]*$" > /dev/null > but it still claims that it is numeric, so *I* must be missing > something. I just realized that I had a stupid mistake there and should have used: if expr "$arg" : "[0-9]*\.[0-9]*$" > /dev/null -- Carl Johnson carlj@peak.org