83.0k views
3 votes
Design an algorithm that prompts the user to enter “yes” or “no” and validates the

input. (Use a case-insensitive comparison.)

In bash shell script code, please.

User WeZZard
by
8.0k points

1 Answer

3 votes

Answer:

#Prompt user for input

read -p "Please enter 'yes' or 'no': " userInput

#Make user input case insensitive

userInput=$(echo "$userInput" | tr '[:upper:]' '[:lower:]')

#Check if userInput is equal to 'yes' or 'no'

if [[ "$userInput" == "yes" || "$userInput" == "no" ]]; then

echo "Input accepted."

else

echo "Input not accepted. Please enter 'yes' or 'no'."

fi

User Initialxy
by
7.7k points