Bash: Simple User Input Yes/No Question

Bash: Simple User Input Yes/No Question

Often in bash you need to ask for user input that requires a yes or no answer. I have tried variations of this. However I found one that worked better than others I have seen. This version will give an error if the user types anything other than y/n/yes/no. Below is an example that I use in all my scripts.

	while true; do
		read -p "Continue? [y/N]" yn
		case $yn in
		[Yy]* ) fn_function;;
		[Nn]* ) exit ;;
		* ) echo "Please answer yes or no.";;
		esac
	done

Source:

http://stackoverflow.com/questions/226703/how-do-i-prompt-for-input-in-a-linux-shell-script