Little Girl's Mostly Linux Blog

Or

Or

This page was last updated on March 06, 2014.
This script uses echo to create the prompt and read to read your answer. It accepts a variety of responses.
#!/bin/bash

echo -n "Do you wish to take that action? (y/n)";
read response;
echo;
if
	[ "$response" = "y" -o "$response" = "Y" -o "$response" = "yes" -o "$response" = "YES" ];
		then
			echo "You chose yes";
elif
	[ "$response" = "n" -o "$response" = "N" -o "$response" = "no" -o "$response" = "NO" ];
		then
			echo "You chose no";
else
	echo "ERROR! ERROR! ERROR! ABORT! ABORT!";
fi;
This script uses read to create the prompt and read your answer. It accepts a variety of responses.
#!/bin/bash

read -s -n1 -p "Do you wish to take that action? (y/n)" keypress;
echo;
if
	[ "$keypress" = "y" -o "$keypress" = "Y" -o "$keypress" = "yes" -o "$keypress" = "YES" ];
		then
			echo "You chose yes";
elif
	[ "$keypress" = "n" -o "$keypress" = "N" -o "$keypress" = "no" -o "$keypress" = "NO" ];
		then
			echo "You chose no";
else
	echo "ERROR! ERROR! ERROR! ABORT! ABORT!";
fi;

Obligatory Happy Ending

And they all lived happily ever after. The end.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Comment:

Blog at WordPress.com.