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

Write a shell script program that will accomplish the following: Display the fol

ID: 3769657 • Letter: W

Question

Write a shell script program that will accomplish the following:

Display the following menu:

------------------------------------------------------------------------------------------------------

Welcome to <>’s menu

1. Display the list of all files in the current directory

2. Run vim

3. See your login id

4. Compare entries in directories

5. Quit Choose your option…..

---------------------------------------------------------------------------------------------

If the user enters option 1, your program should display the list of entries in the current directory. For option 2, run the vim editor. For option 3, provide your login id (only) from the id command. For option 4, your program should prompt the user for the directory he/she wish to compare the number of entries with the current directory, and display the directory name which contains the more entries. If the user enters a directory name which does not exist, your program should state that the directory does not exist. To quit, user will choose option 5. Your program should continue to execute until the user selects option 5.

Explanation / Answer

PrintMenu()
{
echo "Welcome to <>'s menu"
echo " 1. Display the list of all files in the current directory"
echo " 2. Run vim"
echo " 3. See your login id"
echo " 4. Compare entries in directories"
echo " 5. Quit"
echo -n "Choose your option...."
}
GetFileCount()
{
count=0
echo $0
for item in $0/*
do
count=$((count+1))
done
return count
}
option=-1
while [ $option != 5 ]
do
PrintMenu
read option
if [ $option -eq 1 ]
then
bash -c "ls"
elif [ $option -eq 2 ]
then
bash -c "vim"
elif [ $option -eq 3 ]
then
bash -c "id -u"
elif [ $option -eq 4 ]
then
echo "Enter directory name to compare: "
read otherDir
if [ -d "$otherDir" ]
then
currentDirCount=GetFileCount $PWD
otherDirCount=GetFilesCount $otherDir
  
if [ $currentDirCount -lt $otherDirCount ]
then
echo "$PWD"
else
echo "$otherDir"
fi
else
echo "Given directory doesnt exist!"
  
fi
fi
done

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote