Computing.Net > Forums > Unix > Shell Script help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Shell Script help

Reply to Message Icon

Name: jrmontg
Date: September 1, 2006 at 08:22:38 Pacific
OS: Windows 2000 Server
CPU/Ram: Intel Xeon
Product: HP
Comment:

I have a varable that I need to test to see if it is a numeric or a alpha character. How can I do this?
Thanks

jrmontg



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: September 1, 2006 at 08:51:44 Pacific
Reply:

From David Korn, ksh shell inventor. It even handles something like

4.5.4 # which is not numeric

#!/bin/ksh

isnum()
{
case $1 in
( ?([-+])+([0-9])?(.)*([0-9])?([Ee]?([-+])+([0-9])) )
return 0;;
( ?([-+])*([0-9])?(.)+([0-9])?([Ee]?([-+])+([0-9])) )
return 0;;
*) return 1;;
esac
}

isnum $1 && echo "numeric" || echo "NOT numeric"


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Shell Script help

Shell Scripting Help www.computing.net/answers/unix/shell-scripting-help/5020.html

C Shell script help! www.computing.net/answers/unix/c-shell-script-help/3108.html

c shell script help PLEASE www.computing.net/answers/unix/c-shell-script-help-please/4355.html