Date: Thu, 24 Jun 2010 21:42:37 -0700 From: Carl Johnson <carlj@peak.org> To: freebsd-questions@freebsd.org Subject: Re: check for numeric content in a shell script (FreeBSD sh) Message-ID: <878w63n2o2.fsf@cjlinux.localnet> In-Reply-To: <20100624183407.GA49923@holstein.holy.cow> (parv@pair.com's message of "Thu\, 24 Jun 2010 08\:34\:07 -1000") 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>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?878w63n2o2.fsf>