home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / shell / 5183 < prev    next >
Encoding:
Internet Message Format  |  1992-12-30  |  854 b 

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!sam.ksu.ksu.edu!news
  2. From: dudley@sam.ksu.ksu.edu (D U D L E Y)
  3. Newsgroups: comp.unix.shell
  4. Subject: testing if an arg is a number
  5. Date: 30 Dec 1992 04:51:41 -0600
  6. Organization: Kansas State University
  7. Lines: 24
  8. Distribution: world
  9. Message-ID: <1hruvtINNbap@sam.ksu.ksu.edu>
  10. NNTP-Posting-Host: sam.ksu.ksu.edu
  11.  
  12. Was curious, and didn't see it in the FAQ...how would you identify if an
  13. argument to a script is *entirely* numeric?
  14.  
  15. So "12" would return true while "12a" would return false.
  16.  
  17. The only way I found was to use egrep.
  18.  
  19. #!/bin/sh
  20.  
  21. if [ $# > 0 ]
  22. then
  23.  
  24.   if echo $1 | egrep -s "^[0-9]+$"
  25.   then
  26.  
  27.     echo completely numeric
  28.  
  29.   fi
  30.  
  31. fi
  32.  
  33. -- 
  34.                                                     John "Dudley" Hunkins
  35.                                                   dudley@matt.ksu.ksu.edu
  36.