Created
October 16, 2019 07:39
-
-
Save regeda/8770b648ce82b7d27d0d0085a39828e5 to your computer and use it in GitHub Desktop.
Bash Script to test if a variable is numeric
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function isdigit() { | |
local digit='^[+-]?[0-9]+$' | |
if [[ $1 =~ $digit ]]; then | |
return 0 | |
fi | |
return 1 | |
} | |
if isdigit $1; then | |
echo number | |
else | |
echo not a number | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment