All pastes #961050 Raw Edit

Miscellany

public text v1 · immutable
#961050 ·published 2008-03-28 17:18 UTC
rendered paste body

useage="\nUseage: ./Lab_14.sh -i <infile> -o <outfile>\n	-i <infile>	The filename containing the existing data.\n	-o <outfile>	The 
filename you want the output to go to."
options="\n\n		Main Menu\n\n		1) Option 1\n 2) Option 2\n 3) Option 3\n 4) Option 4\n 5) Exit\n Please Select an Option from the 
menu: "
selection=100 							#setting the selection to a number so we dont run into errors


if [ "$#" == "0" ] 						#== means if arguments are = to 0
	then
		echo
		echo "Error: No arguments present at all"
		echo
		echo -e $useage
		exit 10 						#sets error level to 10
fi
if [ "$1" != "-i" ] 					#if Variable 1 is not equal to -i
	then
		echo
		echo "Error: Expecting \"-i\" for the first argument"
		echo
		echo -e $useage
		exit 12
fi
if [ "$2" = "" ] 						#if Variable 2 is not equal to anything
	then
		echo
		echo "Error: Second Argument is missing"
		echo
		echo -e $useage
		exit 13
fi
if [ ! -e $2 ]							#Checks to see if the file exists
	then
		echo
		echo "Error: File Does not exist."
		echo
		echo -e $useage
		exit 14
fi
if [ "$3" = "" ] 						#if there is nothing for 3rd variable is outputs this error
	then
		echo
		echo "Error: Third Argument is missing"
		echo
		echo -e $useage
		exit 15
fi
if [ "$3" != "-o" ] 					#if Variable 3 is not equal to -o it outputs this error
	then
		echo
		echo "Error: Expecting \"-o\" for the third argument"
		echo
		echo -e $useage
		exit 16
fi
if [ "$4" = "" ] 						#if Variable 4 is not equal to anything it outputs this error
	then
		echo
		echo "Error: Fourth argument is missing"
		echo
		echo -e $useage
		exit 17
fi
if [ $# \> 4 ]							#Checks to see if the amount of arguments is grater than 4.
	then
		echo "Too many arguments provided on command line..."
		echo -e $useage
		exit 18			
fi


if [ -e $4 ]							#Checks to see if the file exists, if it does it asks if you wnat to overwrite or not
	then
		echo -e -n "\nMessage: File \"$4\" Already Exists. \nWould you like to overwrite the file? (y/n) "
		read answer 					#loooks for the answer yes or no
		case $answer in
		y) echo -e "\nOverwrite Selected. Overwriting file...";;
		n) echo -e "\nNo Overwtite Selected. Exiting the script..."
		exit 19;;
		*) echo -e "\nInvalid Input selected. Now exiting the script..."
		exit 19;;
		esac
	else
		until [ $selection = 5 ] 		#waits until the selection is 5 then exits the loop
		do
		case selection in
		1) clear; echo -e -n $options	#makes sure the script doesn't exit and waits for the user input.
		read selection 					#reads the selection choosen by the user
		echo -e "\\n Main Menu option \"$selection\" selected. \\n Press the <enter> key to continue..."; read;;
		2) clear; echo -e -n $options
		read selection
		echo -e "\\n Main Menu option \"$selection\" selected. \\n Press the <enter> key to continue..."; read;;
		3) clear; echo -e -n $options
		read selection
		echo -e "\\n Main Menu option \"$selection\" selected. \\n Press the <enter> key to continue..."; read;;
		4) clear; echo -e -n $options
		read selection
		echo -e "\\n Main Menu option \"$selection\" selected. \\n Press the <enter> key to continue..."; read;;
		*) clear; echo -e -n $options
		read selection
		echo -e "\\n Main Menu option \"$selection\" Not valid. You just crashed the script...."; read;;
		exit 19;;
		esac
	clear
	done
	exit
fi

exit