How do i modify this shell script i\'ve been working on, so that choice \"Quit\"
ID: 3684689 • Letter: H
Question
How do i modify this shell script i've been working on, so that choice "Quit" is selected from the menu, it will display my home directories .bashrc file (this program named "MenuProject" is located at densbjstl/FinalProject/MenuProject in my file structure)?
#!/bin/bash
PS3='Please enter your choice:'
options=("Option 1 - File Directory?" "Option 2 - Run MyScript?" "Option 3 - Find
testfile2.txt?" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Option 1 - File Directory?")
echo "File Directory Listing"
ls -1
;;
"Option 2 - Run MyScript?")
echo "myscript File Is Being Executed"
sh ./myscript
;;
"Option 3 - Find testfile2.txt?")
echo "testfile2.txt File Is Being Executed"
find .-name 'testfile2.txt'
;;
"Quit")
break
;;
*) echo invalid option;;
esac
done
~
~
~
~
~
~
~
~
~
~
~
~
"MenuProject" 28L, 514C 20,1 All
Explanation / Answer
we will add statements to the above script:
#!/bin/bash
PS3='Please enter your choice:'
options=("Option 1 - File Directory?" "Option 2 - Run MyScript?" "Option 3 - Find
testfile2.txt?" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Option 1 - File Directory?")
echo "File Directory Listing"
ls -1
;;
"Option 2 - Run MyScript?")
echo "myscript File Is Being Executed"
sh ./myscript
;;
"Option 3 - Find testfile2.txt?")
echo "testfile2.txt File Is Being Executed"
find .-name 'testfile2.txt'
;;
"Quit")
echo ~username
eval echo ~$username->
we can use one of these two to display the home directory for a given user.we can write th username here and get to display the home directory.
break
;;
*) echo invalid option;;
esac
done
~
~
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.