Little Girl's Mostly Linux Blog

CaseTest

Case test

This page was last updated on September 29, 2013.
This script will accept a lower or upper case y or n as a yes or no response. This is done by using the -o switch to perform the or operation.
#!/bin/bash

echo -n "Do you wish to take that action (y/n) ";
read -n1 response;
echo;
if
	[ "$response" = "y" -o "$response" = "Y" ];
then
	echo "You chose yes";
elif
	[ "$response" = "n" -o "$response" = "N" ];
then
	echo "You chose no";
else
	echo "invalid response";
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.