cfe396ea83f5403bbe51b00764fa7fa42cb87a44
2 # Desc: Checks if arg is an integer
4 #==BEGIN Define script parameters==
5 #===BEGIN Declare local script functions===
6 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr
7 die
() { yell
"$*"; exit 111; } # same as yell() but non-zero exit status
8 try
() { "$@" || die
"cannot $*"; } # runs args as command, reports args if command fails
10 # Desc: Checks if arg is integer
13 # Output: - return code 0 (if arg is integer)
14 # - return code 1 (if arg is not integer)
15 # Example: if ! checkInt $arg; then echo "not int"; fi;
20 if [[ $# -ne 1 ]]; then
21 die
"ERROR:Invalid number of arguments:$#";
24 RETEST1
='^[0-9]+$'; # Regular Expression to test
25 if [[ ! $1 =~
$RETEST1 ]] ; then
31 #===Determine function return code===
32 if [ "$returnState" = "true" ]; then
37 } # Checks if arg is integer
39 #===END Declare local script functions===
40 #==END Define script parameters==
43 if checkInt
4; then yell
"success"; fi;
45 if checkInt
"foo"; then yell
"success"; else yell
"fail"; fi;
47 if checkInt
"foo" "bar" "baz" 1; then yell
"success"; else yell
"fail"; fi;
49 if checkInt
; then yell
"success"; else yell
"fail"; fi;
52 # Author: Steven Baltakatei Sandoval