#!/bin/bash # Generate a random number between 1 and 100 target=$((RANDOM % 100 + 1)) attempts=0 echo "Welcome to the Guessing Game!" echo "I have picked a random number between 1 and 100. Try to guess it!" while true; do # Prompt the user for their guess read -p "Enter your guess: " guess attempts=$((attempts + 1)) # Check if the guess is correct if [ "$guess" -eq "$target" ]; then echo "Congratulations! You guessed it in $attempts attempts." break elif [ "$guess" -lt "$target" ]; then echo "Too low! Try again." else echo "Too high! Try again." fi done