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

  1. Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!caen!uwm.edu!rpi!crdgw1!sixhub!davidsen
  2. From: davidsen@sixhub.UUCP (Wm E. Davidsen Jr)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: testing if an arg is a number
  5. Message-ID: <6077@sixhub.UUCP>
  6. Date: 31 Dec 92 12:44:19 GMT
  7. References: <1hruvtINNbap@sam.ksu.ksu.edu>
  8. Reply-To: davidsen@sixhub.UUCP (bill davidsen)
  9. Organization: *IX Public Access UNIX, Schenectady NY
  10. Lines: 18
  11.  
  12. In article <1hruvtINNbap@sam.ksu.ksu.edu> dudley@sam.ksu.ksu.edu (D U D L E Y) writes:
  13. | Was curious, and didn't see it in the FAQ...how would you identify if an
  14. | argument to a script is *entirely* numeric?
  15. | So "12" would return true while "12a" would return false.
  16. | The only way I found was to use egrep.
  17.  
  18. See also expr.
  19.  
  20.   expr "$n" : "^[0-9][0-9]*$" > /dev/null && echo numeric || echo other
  21.  
  22. The output of the expr is the number of digits, thus the redirection.
  23. -- 
  24. bill davidsen - davidsen@sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
  25.     sysop *IX BBS and Public Access UNIX
  26. "I haven't had time to read the manual, I've been too
  27.    busy fighting with the install" -Nevius
  28.