I am trying to create a bash script where I ask for a users age and then the script returns two numbers that sum to their age.
I tried
read -p "Enter your age: " age
echo $RANDOM+$RANDOM="$age"
When running this it printed random numbers that do not equal the age that the user inserted. I was expecting it to print two random numbers that added up to their age.
2
Answers
Well, you can’t use 2 random numbers if their sum must be equal to the given age; one is enough:
The script above first asks for the user’s age using the
echo
and then reads and saves the age using theread
. It will then print two random numbers that when added together equals to the age that the user entered.