I am currently completing a shell script for an assignment in my intro to operating systems class. I have to write a Bourne shell script that allows the user to choose from 2 menu options:
1. Print the users enviromental variables
2. Add to the reminder file
3. Display the contents of the reminder file
4. Display the reminder of the day
5. Exit the Program
The script also has to handle 2 arguments, the first being the name of the file in which the reminders are to be stored and the second argument is the name of the directory which the reminder file is to be placed
I have completed the menu, option 1, option 5 and validated the command line arguments.
The problem I'm having is with option 2, i'm not quite sure how to go about it.
The assignment says that the user should be prompted for the day and description of the new reminder. The input needs to be validated.
•If there is no reminder for the given day in the file the implementation of this command should create a new reminder that takes place on the day, and saved in the reminder file with the format of: day of the week: reminder, eg: Monday: Plan the week
•If there is a reminder for the given day in the file the implementation of this command should ask the user whether to replace the existing one or add to it.
oChallenge: If the response is to replace, the new reminder should replace the existing one for the day.
o If the response is to add, the new reminder needs to be appended to the existing one for the day.
The command should notify the user if successful.
I'm just not sure how to go about so I would be very grateful to anyone who points me in the right direction.
Below is the code I have writen so far (I have excluded the argument validation as it is hard to follow):
--------------------
#!/bin/sh
option=0
notDone=0
while [ $notDone -eq 0 ]
do
echo Please Enter a menu option
echo
echo 1. Print the user enviroment variables
echo 2. Add to the reminder file
echo 3. Display the contents of the reminder file
echo 4. Display the reminder for the day
echo 5. Exit the program
read option
case $option in
1 )
echo
date '+%d/%m/%y'
echo
grep 2553878 /etc/passwd
echo
echo Enviromental Variables:
echo "Home directory: $HOME"
echo "Mail directory: $MAIL"
echo "Path: $PATH"
echo "Login shell: $SHELL"
echo
;;
2 )
;;
3 )
;;
4 )
;;
5 )
notDone=1
;;
* )
echo "Please enter a valid option number"
;;
esac
done
--------------------
Thanx in advanced