On Thu, Jun 24, 2010 at 03:44:34AM +0100, RW wrote:

Hello,

> On Thu, 24 Jun 2010 03:37:55 +0200
> Thomas <f...@gothschlampen.com> wrote:
> 
> > On Thu, Jun 24, 2010 at 09:24:39AM +0800, Aiza wrote:
> > 
> > Hello,
> > 
> > > Receiving a variable from the command line that is suppose
> > > to contain numeric values.
> > > 
> > > How do I code a test to verify the content is  numeric?
> > 
> > http://www.google.com/search?q=shell+test+if+variable+numeric
> > 
> > First link =>
> > http://www.unix.com/shell-programming-scripting/46276-check-variable-if-its-non-numeric.html
> > 
> > Gosh, Google is full of answers these days..
> 
> I'd suggest looking a bit further down the list since the quoted first
> link is patently wrong.

t...@eternity:~$ b=5
t...@eternity:~$ case "$b" in 
> [0-9] ) 
>         echo numeric 
>         ;;
> * ) 
>         echo alpha 
>         ;;
> esac
numeric
t...@eternity:~$

Works for me.

Another solution would be like this:

if echo "$b" | egrep -q '^[0-9]+$'; then

and eventual variants of it.


Regards
Thomas
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to