How to check for a Numeric Value?

Using shell,

I have a variable, how can I check that variable for a numeric value such as "41.0"? My program needs to do one things if the numeric value is found, and another if something else such as a string of letter is found. is there a specific character that denotes a numeral? The numerals will always be a decimal number rounded to the tenth as above. Some numerals could be five digits though, including the decimal, such as "376.0". Can anyone help me?

one way:

var=123.1
check=$(echo "$var" | tr -d '[:digit:]' | tr -d '.')
if [  -z "$check" ]; then
      echo 'is all digits'
else
      echo 'is not all digits'
fi
2 Likes
$ echo 123.5 | tr -d [:alpha:]
123.5

$ echo alpha | tr -d [:alpha:]

$