Bash Hack - Testing to see if a variable is an integer

Bash unfortunately does not include a built-in function to test if a variable is an integer. There is however a simple pattern matching hack that you can use to test this on your own:

Check for Unsigned Integer

[[ $number =~ ^[0-9]+$ ]] && echo -e "match found : integer\n"

Check for Signed Integer

[[ $number =~ ^[+-]?[0-9]+$ ]] && echo -e "match found : (signed) integer\n"