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.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Comment:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: