making a rock paper scissors game to learn better bash. For some reason it's not liking my elif statements and I can't figure out why. Also if there are any better ways of doing this let me know, thanks!
#!/bin/bash
#rock beats scissors, scissors beats paper, paper beats rock,
printf "Welcome to rock paper scissors. Type 'r', 'p', or 's' to start: "
#get users selection
read user
#detect input and assign it to a num that will be used to check against computer.
if [[ $user == [rR] || $user == "Rock" || $user == "rock" ]]
then
user="r"
elif [[ $user == [sS] || $user == "scissors" || $user == "Scissors" ]]
then
user="s"
elif [[ $user == [pP] || $user == "paper" || $user == "Paper" ]]
then
user="p"
else
printf "Not a valid submission, you entered: $user\n"
fi
#get random number between 1 and 9
comp=$(shuf -i 1-9 -n 1)
#detect what number it was and assign either r p s to it.
if ((1<=$comp && $comp<=3))
then
comp="r"
printf "Rock\n"
elif ((4<=$comp && $comp<=6))
then
comp="s"
printf "Scissors\n"
elif ((6<=$comp && $comp<=9))
then
comp="p"
printf "Paper\n"
else
echo "not in range?"
fi
#find out who won
if [[ $user == $comp ]]
then
echo "same!"
elif [[ $user == "r" && $comp == "p" ]]
echo "user rock comp paper COMP WINS"
elif [[ $user == "p" && $comp == "r" ]]
echo "comp rock user paper USER WINS"
elif [[ $user == "s" && $comp == "r" ]]
echo "user scissors comp rock COMP WINS"
elif [[ $user == "r" && $comp == "s" ]]
echo "user rock comp scissors USER WINS"
elif [[ $user == "p" && $comp == "s" ]]
echo "user paper comp scissors COMP WINS"
elif [[ $user == "s" && $comp == "p" ]]
echo "user scissors comp paper USER WINS"
else
echo "something is borked"
fi
And I get this error:
./rps.sh: line 49: syntax error near unexpected token `elif'
./rps.sh: line 49: `elif [[ $user == "p" && $comp == "r" ]]'