Skip to content

Instantly share code, notes, and snippets.

@regeda
Created October 16, 2019 07:39
Show Gist options
  • Save regeda/8770b648ce82b7d27d0d0085a39828e5 to your computer and use it in GitHub Desktop.
Save regeda/8770b648ce82b7d27d0d0085a39828e5 to your computer and use it in GitHub Desktop.
Bash Script to test if a variable is numeric
#!/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