check for numeric content in a shell script (FreeBSD sh)

Chip Camden sterling at camdensoftware.com
Thu Jun 24 19:23:02 UTC 2010


On Jun 24 08:39, Parv wrote:
> in message <20100624183407.GA49923 at holstein.holy.cow>,
> wrote parv at pair.com thusly...
> >
> > #  Matches a number, either positive (without '+' sign) or
> > #  negative, which is either a whole number; or a real number
> > #  ending with decimal point, or a real number with or without
> > #  leading digits before the decimal point.
> .                 ^
> .                 ^  plural
> > ^
> > -?
> > (
> >   [0-9]  [.]? [0-9]*
> >     |
> >   [0-9]? [.]  [0-9]+
> .        ^
> .        ^  oops
> 
> Please change the immediately above regex portion to ...
> 
>   [0-9]* [.]  [0-9]+
> 
> 
>   - parv

We still need to be able to handle numbers without a decimal.  Try this:

	[0-9]*\.?[0-9]+

The question mark says "0 or 1"
> 
> > )
> > $
> 
> -- 
> 
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"

-- 
Sterling (Chip) Camden
http://camdensoftware.com | http://chipstips.com | http://chipsquips.com


More information about the freebsd-questions mailing list