| T.R | Title | User | Personal Name
 | Date | Lines | 
|---|
| 9736.1 |  | EVTAI1::SAMIE_F | francoise     [email protected] | Wed May 07 1997 05:01 | 2 | 
|  | expr can do it. Try 
if    [ `expr $1 + 1` ] then ...
 | 
| 9736.2 | Some alternatives | UNIFIX::HARRIS | Juggling has its ups and downs | Wed May 07 1997 09:33 | 50 | 
|  |     .1 is good, but it outputs an error message when not numeric.  That
    could be fixed by redirecting stderr into /dev/null
    
    	if expr $1 + 1 >/dev/null 2>&1
    	then
    	    	echo numeric
    	fi
    
    Or try:
    
    	if [ -n "`expr $1 : '^\([0-9][0-9]*\)$'`" ]
    	then
    		echo numeric
        fi
    
    Or if you know the max number of digits you could try
    
    	case $1 in
    	    [0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9])
    		echo number is 1 to 4 digits in length
    		;;
    	    *)
    		echo not numeric
    		;;
    	esac
    
    You can extend the [0-9]... expression for as large as you need.  This
    stays within the shell and does not create a new process.
    
    Also you could put your testing in to a borne shell function and make
    then not have to repeat the messy code all over the place, just call
    the function
    
    	is_numeric() {
    	    if [ -n "`expr $1 : '^\([0-9][0-9]*\)$'`" ]
    	    then
    		return 0	# borne shell 0 is true
    	    else
    		return 1	# borne shell 1 is false
    	    fi
    	}
    
    	if is_numeric $1
    	then
    		echo is numeric
    	fi
    
    I'm sure there are other clever ways to do this.
    
    					Bob Harris
 | 
| 9736.3 | why didn't i think of '^\([0-9][0-9]*\)$' ;-) | GIDDAY::STRAUSS | talking through my binoculars | Wed May 07 1997 18:12 | 9 | 
|  |     Thanks for both replies.
    
    if [ -n "`expr $1 : '^\([0-9][0-9]*\)$'`" ]
    
    looks like a winner, if only for the obscurity of the syntax ;-)
    
    Thanks again
    
    	leon
 | 
| 9736.4 | confused about your locale problems | SMURF::WENDY |  | Thu May 08 1997 14:26 | 7 | 
|  |     What makes you think LC_CTYPE is not being set ? Did you check using
    the locale command ? The 8859-* based locales are in an optional
    subset. IF you set LANG to en_US.ISO8859-1 and it is not installed on
    the system LANG and all the LC_* env varibales default to be C. 
    
    wendy
    
 | 
| 9736.5 | whoops! | GIDDAY::STRAUSS | talking through my binoculars | Thu May 08 1997 17:36 | 13 | 
|  |     Hi Wendy
    
    Sorry, my base note was written in haste (and not a little confusion).
    locale _did_ set LC_CTYPE="C" and LC_CTYPE="en_US.ISO8859-1" for LANG=C
    and LANG=en_US.ISO8859-1 respectively - I didn't check properly :-(
    
    My test using [[:digit:]] probably failed for some other
    brain-fade-related reason ...  Next time, I'll double-check before
    posting.
    
    Thanks
    
    	leon
 | 
| 9736.6 |  | BIGUN::nessus.cao.dec.com::Mayne | A wretched hive of scum and villainy | Thu May 08 1997 18:18 | 5 | 
|  | You forgot to check for a leading "-".
Is "3.14" numeric, or are you just interested in integers?
PJDM
 | 
| 9736.7 | Just positive integers | GIDDAY::STRAUSS | talking through my binoculars | Sun May 11 1997 22:27 | 1 | 
|  |     Just positive integers
 |