jeudi 28 mars 2019

Compare number to string/ or change datatype

I have a file with numbers such as 2,3,4,5 never greater than 5 or lower than 2. I read them in using a loop. My if statement do not work and i narrow it down to what i think is differents datatype.

I can't use -eq because it causes an invalid arithmetic operator error.

#!bin/bash

while read -r number
do
if [[ $number == 2 ]]
then
    echo "found two"
 elif [[ $number == 3 ]]
    echo "found three"
 elif [[ $number == 4 ]]
    echo "found four"
else [[ $number == 5 ]]
    echo "found five"
fi
done < $1

Whenever it matches 2,3,4 or 5 it should be found a match. I know it sounds dumb but I just want to be able to get it to compare.

Aucun commentaire:

Enregistrer un commentaire