Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Menu system for Unix shell that provides the following functionality: 1

ID: 3572021 • Letter: C

Question

Create a Menu system for Unix shell that provides the following functionality: 1. Allows users to select from 6 different choices including: a. Display the current date and time. b. List all of the files along with the size of the file in the user's home directory c. List the last 5 lines of a file in the user's home directory. Note: the user should be prompted for the name of the file. d. Prompt the user for his/her favorite color. When prompted for this a sub-menu should provide a list of up to 8 colors to choose. e. One more additional menu selection to be fully implemented by the developer of his/her choice. f. Exit the program 2. Each menu should be separated into functions where appropriate. 3. The selections should be cleared between menu selections making the screen neat and well-organized. 4. When possible, separate functions should be called for each of the menu functionality. 5. A looping structure should be used to ensure the script will run until the user exits the system.

Explanation / Answer

themenu ()
{
echo "a. Display the current date and time."
echo "b. List all of the files along with the size of the file in the user's home directory"
echo "c. List the last 5 lines of a file in the user's home directory."
echo "d. Prompt the user for his/her favorite color."
echo "e. One more additional menu selection to be fully implemented by the developer of his/her choice."
echo "f. Exit the program"
echo "Enter your choice";
}
today()
{
echo "Today is $(date)"
}

dir()
{
ls -FaGl "${@}" | awk '{ total += $4; print }; END { print total }';
}

file()
{
echo -n "Enter File Name : "
read fileName
# make sure file exits for reading
if [ ! -f $fileName ]; then
echo "Filename $fileName does not exists"
exit 1
fi
# display last five lines of the file using tail command
tail -5 $fileName
}
color()
{
echo "1. Violet"
echo "2. Indigo"
echo "3. Blue"
echo "4. Green"
echo "5. Yellow"
echo "6. Orange"
echo "7. Red"
echo "8. Black"
echo "Enter your choice";
read colo
}
while true
do
# 1. display the menu
themenu
# 2. read a line of input from the keyboard
read answer
case $answer in
a|A) today;;
b|B) dir;;
c|C) file;;
d|D) color;;
e|E) echo "Point is not clear";;
f|F) break;;
*) echo invalid option;;
esac
done

e point is not clear.