]>
git.ipfire.org Git - thirdparty/bash.git/blob - examples/functions/isnum.bash
1eff13fb40abf06261dedb6361aeae7069c6ad1d
1 #From: jrmartin@rainey.blueneptune.com (James R. Martin)
2 #Newsgroups: comp.unix.shell
3 #Subject: Re: testing user input on numeric or character value
4 #Date: 26 Nov 1997 01:28:43 GMT
6 # isnum returns True if its argument is a valid number,
7 # and False (retval=1) if it is any other string.
8 # The first pattern requires a digit before the decimal
9 # point, and the second after the decimal point.
11 # BASH NOTE: make sure you have executed `shopt -s extglob' before
12 # trying to use this function, or it will not work
14 function isnum
# string
17 ?
([-+])+([0-9])?
(.
)*([0-9])?
([Ee
]?
([-+])+([0-9])) )
19 ?
([-+])*([0-9])?
(.
)+([0-9])?
([Ee
]?
([-+])+([0-9])) )