My assignment requires me to use $RANDOM and compare it to users input until it matches. I'm currently using if statement to see if the $RANDOM function works, it does but i'm not sure if im comparing the value to the users input correctly because i keep getting syntax errors.
./rec04C.sh
Enter a number between 1 and 10: 6
8
./rec04C.sh: line 8: [8: command not found
Sorry, you are not correct. Try again!
For this above code the 3rd line is a result of the 6th line in my bash script, and the error comes from the comparison on line 8. But it still produces the output of the else statement
#!/bin/bash
read -p "Enter a number between 1 and 10: " number
rand=$((1 + $RANDOM % 10))
echo $rand
if [$rand -eq $number]; then
echo "Congratulations, the number is $number"
else
echo "Sorry, you are not correct. Try again!"
fi
Aucun commentaire:
Enregistrer un commentaire