check_dec=^[0-9]*\.+[0-9]+
input=0
echo "Please enter a digit: "
read input
if [[ $input =~ $check_dec ]]
then
echo "The value is a decimal"
else
echo "The value is an integer"
fi
I am trying to store a regex in the variable "check_dec" to validate the users input. I am having trouble understanding why any non-single-digit value I enter enters the "if" statement and reads "The value is a decimal"
As an example, when I type (44, 100, 1000, etc.), the output is "The value is a decimal" However, when I enter a single digit number the output reads "The value is an integer"
I'm brand new to regex/bash and don't fully understand . Any help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire