Page 1 of 1

Checking if an input number is an integer in shell scripts

Posted: Fri Sep 04, 2020 6:01 pm
by cah
This is the code to check if the input/variable is an integer in shell scripts:

Code: Select all

if ! [[ "$input" =~ ^[0-9]+$ ]]
then
    echo "Sorry integers only"
fi