I have an alphanumeric string, say something like “XXXX24Y2” from which i have extracted only the numbers and assigned them to 2 variables, say num1 and num2, say num1=24 and num2=2
Now i want to check (if num1 <=24 and num2 <2); then do something. I have tried all kinds of brackets double, single, square, with quotes around the variable, without etc. I dont get any errors. Its just that bash wont read that if statement.
My code is something like this:
#!/bin/bash
NEW_BR_NAME=$1
TAG=$2
j_name=$3
echo $1 > brname.txt
brname=$(cat brname.txt | cut -c1-8)
if [[ "$3" == "git" ]]; then
grep -q "ABC3" brname.txt && echo "Its ABC3"
read num1 num2 <<<${brname//[^0-9]/ }
echo "num1=$num1 num2=$num2"
if [[ $num1 <= 24 && $num2 < 2 ]]; then
echo "something to print"
exit 1
fi
fi
My code works perfectly fine till echo “num1=$num1 num2=$num2” but there are no errors and the next if statement is not understood by bash shell. how do i check if $num1 <=24 adn $num2 <2 in this case? what am i doing wrong?