home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!sam.ksu.ksu.edu!news
- From: dudley@sam.ksu.ksu.edu (D U D L E Y)
- Newsgroups: comp.unix.shell
- Subject: testing if an arg is a number
- Date: 30 Dec 1992 04:51:41 -0600
- Organization: Kansas State University
- Lines: 24
- Distribution: world
- Message-ID: <1hruvtINNbap@sam.ksu.ksu.edu>
- NNTP-Posting-Host: sam.ksu.ksu.edu
-
- 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.
-
- #!/bin/sh
-
- if [ $# > 0 ]
- then
-
- if echo $1 | egrep -s "^[0-9]+$"
- then
-
- echo completely numeric
-
- fi
-
- fi
-
- --
- John "Dudley" Hunkins
- dudley@matt.ksu.ksu.edu
-