Sometime in bash scripts, we need to check digits, integers and floating values. it is quite easy to do that that with one simple expression.let’s see with one examples.


#!/bin/bash
read -p “Type a integer :” number
if [[ $number =~ ^[+-]?[0-9]*$ ]];then
echo “Number is integer”

elif [[ $number =~ ^[+-]?[0-9]+\.?[0-9]*$ ]];then
echo “Number is float ”

else
echo “Try Once more”
fi
=====================================
        OutPut
#./integer_float
Type a integer :12
Number is integer

#./integer_float
Type a integer :-12
Number is integer

#./integer_float
Type a integer :+12
Number is integer

#./integer_float
Type a integer :-12.23
Number is float

#./integer_float
Type a integer :+12.23
Number is float

#./integer_float
Type a integer :12.23
Number is float

#./integer_float
Type a integer :868ylnk
Try Once more

With this we easily able to identify integer or float values in bash scripts.