[NTLUG:Discuss] basic Bash question
    Chris Cox 
    cjcox at acm.org
       
    Fri Aug  6 22:38:32 CDT 2004
    
    
  
Lance Simmons wrote:
> I need to test whether a string is an integer.
> 
> I'm tailing a logfile and extracting a string.  99 times out of 100 the
> string is an integer, but sometimes, because of the program that creates
> the logfile, it's not an integer.
> 
> Is there a simple way in a bash script to test whether a string is an
> integer?
> 
a=10
b=String
if expr $a + 1 >/dev/null 2>&1; then
   echo "a in an integer"
fi
if expr $b + 1 >/dev/null 2>&1; then
   echo "b in an integer"
fi
    
    
More information about the Discuss
mailing list