Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. scorefile="highscores_bash"
  2. guess=-1
  3. typeset -i num=0
  4.  
  5. echo -e "guess.bash - Guess a number between 1 and 100\n"
  6.  
  7. ### Generate random number
  8. (( answer = RANDOM % 100 + 1 ))
  9.  
  10. ### Play game
  11. while (( guess != answer )); do
  12. num=num+1
  13. read -p "Enter guess $num: " guess
  14. if (( guess < answer )); then
  15. echo "Higher..."
  16. elif (( guess > answer )); then
  17. echo "Lower..."
  18. fi
  19. done
  20. echo -e "Correct! That took $num guesses.\n"
  21.  
  22. ### Save high score
  23. read -p "Please enter your name: " name
  24. echo $name $num >> $scorefile
  25.  
  26. ### Print high scores
  27. echo -e "\nPrevious high scores,"
  28. cat $scorefile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement