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