You are to create a simple menu driven “shell.” Your shell should present a list
ID: 3590770 • Letter: Y
Question
You are to create a simple menu driven “shell.” Your shell should present a list of options to the user of alternative actions they are allowed to perform. The list should be a set of menu items. The user can choose one of the items, it executes, and then the shell presents the list again. As a minimum, your shell should allow the user to choose between (1) executing the ‘who’ command, (2) running an editor, (3) listing the contents of the current directory, and (4) logging off.
Note: If your shell is installed in the ’passwd’ file as the default shell, when you exit the program it will log off the user.
Your menu should look something like:
Your choices are:
[1] list the users currently on the system
[2] running the ed editor
[3] list the files in the current directory
[4] log off
What is your choice (type the number):
The expectation is that the user will type one of the numbers 1 to 4, the shell will act as a parent to create a child process, the child will execute the appropriate programs, and then, when the child terminates, the parent will display the menu again.
You may add to the list of actions. The choice of editor is up to you, the programmer. Good programming practices (indenting, commenting, etc.) are expected!
As in the previous programming assignment, leave the file on the system and submit the source code filename and path.
Explanation / Answer
#!/bin/bash
clear
while true
do
echo " Your choices are:"
echo " 1. list the users currently on the system"
echo " 2. running the ed editor"
echo " 3. list the files in the current directory"
echo " 4. log off"
echo " What is your choice (type the number): c"
read Choice #Storing user choice in variable Choice
case $Choice in
1) sudo who;; #Here the who command is standard Unix command who displays a list of users who are currently logged into the computer.
2) sudo ed;; #Command to Load the ed editor
3) sudo ls -la;; #Showing list of files in current directory
4) user=$(whoami) #Firstly storing the cuurent logged username in variable user
sudo pkill -KILL -u $user;; #Using the user variable to kill it rather logg off.
esac
done
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.