#/bin/bash

# demoscript3.sh
# Script to demo use of while loop, for loop, and case statement
# P. TenHoopen, 01/29/08

clear

while [ 1 ]  # loop forever
do
	echo
	echo "Menu"
	echo
	echo "Option 1 - List temp files"
	echo "Option 2 - Delete temp files"
	echo
	
	echo -n "Enter your choice (q to quit): "
	
	read input
	
	case "$input" in
	
		"1" )
		echo
		echo "Listing temp files in current directory"
		echo
		ls *.tmp
		;;
		
		"2" )
		echo
		echo "Preparing to delete temp files in current directory"
		echo
		echo -n "OK to continue? (y/n): "
		read ans
		if [[ $ans = "Y" || $ans = "y" ]] 
		then
			echo "Deleting temp files in current directory..."
			for filename in *.tmp
			do
				echo "Deleting file $filename"
				rm -f $filename
			done
		fi
		;;
		
		"q" | "Q" )
		echo
		break
		;;
		
		* )
		echo
		echo "Invalid option"
		;;
	
	esac
done
