Thought i'd follow this thread up with my exam.
Thanks for the help on the if statements, i wasn't paying attention in class and hadn't noticed that each if needs a then.
heres the segment of code we had to write for our exam(or at least my version)
#!/bin/bash
#Must accept 1 commandline either --usermenu or --adminmenu else display error message.
x=0 #used to return to menu after completing task one
if [ "$#" -eq "1" ] # checking to see only 1 arguement on the script
then
if [ "$1" == "--usermenu" ] # checking to see if arguement matches
then
#generating menu options
while [ "$x" -eq "0" ] #traps user in the menu
do
echo " User Tasks"
echo " ---------"
echo " 1) Email yourself the (/etc/passwd) File"
echo
echo " 2 ) Exit"
echo
echo "Please enter a menu option:1/2"
read user #gathers user input for case
case $user in
1)
mail -s "Here is the /etc/passwd file " whoami </etc/passwd
clear #clears and re-writes menu for user
;;
2 ) let x=x+1 # sets user free from menu
clear
;;
esac
done
elif [ "$1" == "--adminmenu" ]
then
while [ "$x" -eq "0" ] #traps user in the menu
do
echo " Admin Tasks"
echo " -----------"
echo " A) Email yourself the (/etc/shadow) File"
echo
echo "

Exit"
echo
echo "Please enter a menu option:a/b "
read admin #gathers user input for case
case $admin in
a) mail -s "Here is the /etc/shadow file" whoami < /etc/shadow
clear # clears terminal and re-writes menu options
;;

let x=x+1 #releases user from menu
clear
;;
esac
done
elif [ "$1" != "--adminmenu" ] && [ "$1" != "--usermenu" ] #checks if only arguement is not a valid option
then
clear
echo "Errorlevel: 200"
fi # end if statement pertaining to only 1 arguement
elif [ "$#" -lt "1" ] #checks if there is less than 1 option
then
clear
echo "errorlevel: 100"
elif [ "$#" -gt "1" ] #checks if there is more than 1 option
then
clear
echo "errorlevel: 150"
fi #end of full if statement & script.
Its got pointless comments in it as i was never very good at commenting my code.
Essentially its initialized by the command ./Final.sh with either --usermenu or --adminmenu as the argument.
It then provides a small menu of user or administrative tasks(obviously very small for the sake of it being an exam).
The only thing i didn't get on this(so either 22/24 or 23/24) to the best of my knowledge, is you needed to get the email to go to the current user using a bash command to always have current user.
Wasn't sure what command that was so i just threw whoami in. It didn't work however the email still ended up in my mail box as it returned to sender for invalid recipient.
e/ the face is case 2.
This post was edited by psrocks on Apr 18 2013 07:20pm