I’m working on a bash script to basically play Rock Paper Scissors against the CPU.
The problem I’m having is that I can’t get it to randomly pick between variables, instead it just picks the first variable noted. Here is the section of code that needs work:
r="rock"
p="paper"
s="scissors"
RPS=$r||$p||$s #The line that needs to be fixed
#rps=$r||$p||$s works but only outputs rock...
echo $RPS
I’ve tried looking for ways to do this on forums but google only pops up forums for randomly picking lines from another file and not within the file itself.
How about something like this:
Discussion
Bash has a built-in variable called $RANDOM, which returns a random integer.