check for numeric content in a shell script (FreeBSD sh)
Carl Johnson
carlj at peak.org
Fri Jun 25 04:42:49 UTC 2010
parv at 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 at peak.org
More information about the freebsd-questions
mailing list