Checking if an input number is an integer in shell scripts

Moderator: cah

Post Reply
cah
General of the Army / Fleet Admiral / General of the Air Force
General of the Army / Fleet Admiral / General of the Air Force
Posts: 1342
Joined: Sun Aug 17, 2008 5:05 am

Checking if an input number is an integer in shell scripts

Post 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
CAH, The Great
Post Reply