.sh check for numeric content

Thomas Keusch fwd at bsd-solutions-duesseldorf.de
Thu Jun 24 11:50:37 UTC 2010


On Thu, Jun 24, 2010 at 11:58:05AM +0100, RW wrote:
> On Thu, 24 Jun 2010 05:19:53 +0200
> Thomas Keusch <fwd at bsd-solutions-duesseldorf.de> wrote:
> 
> > tk at eternity:~$ b=5
> > tk at eternity:~$ case "$b" in 
> > > [0-9] ) 
> > >         echo numeric 
> > >         ;;
> > > * ) 
> > >         echo alpha 
> > >         ;;
> > > esac
> > numeric
> > tk at eternity:~$
> > 
> > Works for me.
> 
> Now try it with 10.

"10" is not valid input according to the problem/pseudocode (in the forum)
that the above code was posted as a solution for.

I tend to lend a hand, not the whole arm. If this doesn't solve the
problem 100% for the OP, it surely enables him to quickly spot a
solution (at least using the case statement) when he sees it, be it in
results from researching via google, or in actual system scripts
installed on his system.

"Give a man a fish, ..." and all that.

Don't get me wrong, I'm not at all against posting more complete solutions
for more complex problems, but I do indeed think that lending a hand while
still requiring a little thought and maybe tinkering on the side of the OP
is what ultimately enables him (& newcomers in general) to learn and grow.

Spoonfeeding solutions to trivial (and trivially researched questions)
is counterproductive on so many levels.

Regards,
Thomas


More information about the freebsd-questions mailing list