diff options
Diffstat (limited to 'examples/functions/isnum.bash')
-rw-r--r-- | examples/functions/isnum.bash | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/examples/functions/isnum.bash b/examples/functions/isnum.bash index 1eff13f..b733965 100644 --- a/examples/functions/isnum.bash +++ b/examples/functions/isnum.bash @@ -11,7 +11,7 @@ # BASH NOTE: make sure you have executed `shopt -s extglob' before # trying to use this function, or it will not work -function isnum # string +isnum() # string { case $1 in ?([-+])+([0-9])?(.)*([0-9])?([Ee]?([-+])+([0-9])) ) @@ -21,3 +21,32 @@ function isnum # string *) return 1;; esac } + +isnum2() # string +{ + case $1 in + ?([-+])+([[:digit:]])?(.)*([[:digit:]])?([Ee]?([-+])+([[:digit:]])) ) + return 0;; + ?([-+])*([[:digit:]])?(.)+([[:digit:]])?([Ee]?([-+])+([[:digit:]])) ) + return 0;; + *) return 1;; + esac +} + +isint() # string +{ + case $1 in + ?([-+])+([0-9]) ) + return 0;; + *) return 1;; + esac +} + +isint2() # string +{ + case $1 in + ?([-+])+([[:digit:]]) ) + return 0;; + *) return 1;; + esac +} |