From owner-freebsd-questions@FreeBSD.ORG Thu Jun 24 16:14:49 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 5FA52106564A for ; Thu, 24 Jun 2010 16:14:49 +0000 (UTC) (envelope-from sterling@camdensoftware.com) Received: from wh2.interactivevillages.com (wh2.interactivevillages.com [75.125.250.34]) by mx1.freebsd.org (Postfix) with ESMTP id 2B4718FC13 for ; Thu, 24 Jun 2010 16:14:48 +0000 (UTC) Received: from 174-21-99-21.tukw.qwest.net ([174.21.99.21] helo=_HOSTNAME_) by wh2.interactivevillages.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1ORovj-0004UY-US for freebsd-questions@freebsd.org; Thu, 24 Jun 2010 09:05:35 -0700 Received: by _HOSTNAME_ (sSMTP sendmail emulation); Thu, 24 Jun 2010 09:14:39 -0700 Date: Thu, 24 Jun 2010 09:14:39 -0700 From: Chip Camden To: freebsd-questions@freebsd.org Message-ID: <20100624161439.GD557@libertas.local.camdensoftware.com> Mail-Followup-To: freebsd-questions@freebsd.org References: <4C22B3D7.6070102@comclark.com> <20100624033257.2D074BEA6@kev.msw.wpafb.af.mil> <20100624050832.06ef2a46@scorpio> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100624050832.06ef2a46@scorpio> User-Agent: Mutt/1.4.2.3i Company: Camden Software Consulting URL: http://camdensoftware.com X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - wh2.interactivevillages.com X-AntiAbuse: Original Domain - freebsd.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - camdensoftware.com Subject: Re: .sh check for numeric content 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: Thu, 24 Jun 2010 16:14:49 -0000 On Jun 24 05:08, Jerry wrote: > On Wed, 23 Jun 2010 23:32:57 -0400 (EDT) > Karl Vogel articulated: > > > > >> On Thu, 24 Jun 2010 09:24:39 +0800, > > >> Aiza 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