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: 3571478 • 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

import os import time def show_time_date(): now = time.strftime("%c") print "Current date & time " + time.strftime("%c") def show_home_directory(): from os.path import expanduser home = expanduser("~") print os.listdir(home) def show_last_five(): from os.path import expanduser home = expanduser("~") print "enter file name" filename = raw_input() full_file_name = os.path.join(home,filename) os.system("tail -n 5 %s" % full_file_name) def select_fav_color(): print "List of available colors" print "1.Red 2.Black 3.blue 4.green 5.white 6.yellow 7.maroon 8.violet" print "select color" col = raw_input() print col def show_first_five(): from os.path import expanduser home = expanduser("~") print "enter file name" filename = raw_input() full_file_name = os.path.join(home,filename) os.system("head -5 %s" % full_file_name) def exit_program(): exit(1) while (1): print "Menu" print"1.show time and date 2.show home directory files 3.show last five lines of a file 4.select favourite color 5.show first five lines of a file 6.exit the program" choice = raw_input() mycase = { '1' : show_time_date, #do not use () '2' : show_home_directory, #do not use () '3' : show_last_five, #do not use () '4' : select_fav_color, '5' : show_first_five, '6' : exit_program } myfunc = mycase[choice] myfunc() os.system('cls')