From owner-freebsd-questions@FreeBSD.ORG Fri Jun 25 04:42:48 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 E5C0B106564A for ; Fri, 25 Jun 2010 04:42:48 +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 B9EA18FC19 for ; Fri, 25 Jun 2010 04:42:48 +0000 (UTC) Received: from peak-mail-gateway.peak.org ([69.59.192.42]) by redcondor1.peak.org ({e03e86cd-14ae-47ce-9578-3c080ce9c462}) via TCP (outbound) with ESMTP id 20100625044247919 for ; Fri, 25 Jun 2010 04:42:47 +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 o5P4ghu4028713 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Thu, 24 Jun 2010 21:42:47 -0700 (PDT) Received: from carlj by cjlinux.localnet with local (Exim 4.69) (envelope-from ) id 1OS0kP-0003BF-N4 for freebsd-questions@freebsd.org; Thu, 24 Jun 2010 21:42:37 -0700 To: freebsd-questions@freebsd.org References: <4C22B3D7.6070102@comclark.com> <20100624033257.2D074BEA6@kev.msw.wpafb.af.mil> <87lja4mlme.fsf@cjlinux.localnet> <87hbksmk6y.fsf@cjlinux.localnet> <87d3vgmj1s.fsf@cjlinux.localnet> <20100624183407.GA49923@holstein.holy.cow> From: Carl Johnson Date: Thu, 24 Jun 2010 21:42:37 -0700 In-Reply-To: <20100624183407.GA49923@holstein.holy.cow> (parv@pair.com's message of "Thu\, 24 Jun 2010 08\:34\:07 -1000") Message-ID: <878w63n2o2.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: check for numeric content in a shell script (FreeBSD sh) 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: Fri, 25 Jun 2010 04:42:49 -0000 parv@pair.com writes: >> if expr "$arg" : "[1-9]*\.\{0,1\}[0-9]*$" > /dev/null > > That regex considers "." a number but not "0.9" (this one seems to > be due to typo) nor a negative number. I had been pointing out an error in the regular expression that someone else had posted, but I obviously didn't do any better. > I would personally to use egrep or awk (printf "%s" "${arg}" | egrep > "${regex}" [0]) instead of expr. I would probably just perl for the whole thing, especially seeing the limitations in trying to use expr. Thanks for pointing out another approach. -- Carl Johnson carlj@peak.org