Date: Thu, 24 Jun 2010 09:14:39 -0700 From: Chip Camden <sterling@camdensoftware.com> To: freebsd-questions@freebsd.org Subject: Re: .sh check for numeric content Message-ID: <20100624161439.GD557@libertas.local.camdensoftware.com> In-Reply-To: <20100624050832.06ef2a46@scorpio> References: <4C22B3D7.6070102@comclark.com> <20100624033257.2D074BEA6@kev.msw.wpafb.af.mil> <20100624050832.06ef2a46@scorpio>
next in thread | previous in thread | raw e-mail | index | archive | help
On Jun 24 05:08, Jerry wrote: > On Wed, 23 Jun 2010 23:32:57 -0400 (EDT) > Karl Vogel <vogelke+unix@pobox.com> articulated: > > > > >> On Thu, 24 Jun 2010 09:24:39 +0800, > > >> Aiza <aiza21@comclark.com> said: > > > > A> Receiving a variable from the command line that is suppose to > > A> contain numeric values. How do I code a test to verify the > > A> 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 > > I had used this snippet in a script to test for numeric input. It was > part of a function in a Bash script. > > case "${1}" in > [[:digit:]] ) > IS_DIGIT=1 > ;; > * ) > IS_DIGIT=0 > printf "\n\a\t *****WARNING***** > \tYou must enter a digit\n\n" > ;; > esac That [[:digit:]] pattern only works if your shell supports POSIX character classes in the case statement. > > -- > Jerry ??? > FreeBSD.user@seibercom.net > > Disclaimer: off-list followups get on-list replies or get ignored. > Please do not ignore the Reply-To header. > __________________________________________________________________ > > Why do we want intelligent terminals > when there are so many stupid users? > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" -- Sterling (Chip) Camden http://camdensoftware.com | http://chipstips.com | http://chipsquips.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100624161439.GD557>