I am having trouble with my Linux Bash programming and in need of some help; bel
ID: 3714786 • Letter: I
Question
I am having trouble with my Linux Bash programming and in need of some help; below are the requirements that need to be met, please help Thank you
1. Display the user a nicely structured menu with five items.
2. The first three items will execute a bash utility. You may use the examples in the command_menu sample program in your text.
3. The fourth item should execute a bash utility of your choice, but not one included in the command_menu example
4. The final item should allow the user to exit the program
5. The menu should use a 'case' control structure to make the selection
6. The menu should run inside a control structure (i.e. loop) allowing multiple menu choices until the user chooses to quit.
Explanation / Answer
pause(){
read -p "Press [Enter] key to continue..." fackEnterKey
}
user_confirm(){
e_header "I am a sample script"
seek_confirmation "Do you want to print a success message?"
if is_confirmed; then
e_success "Here is a success message"
else
e_error "You did not ask for a success message"
fi
pause
}
# do something in two()
two(){
echo "two() called"
pause
}
pushover () {
PUSHOVERURL="https://abc.com/1/messages.json"
API_KEY="your-api-here"
USER_KEY="your-user-key-here"
DEVICE=""
TITLE="${1}"
MESSAGE="${2}"
curl
-F "token=${API_KEY}"
-F "user=${USER_KEY}"
-F "device=${DEVICE}"
-F "title=${TITLE}"
-F "message=${MESSAGE}"
"${PUSHOVERURL}" > /dev/null 2>&1
}
# function to display menus
show_menus() {
clear
echo "~~~~~~~~~~~~~~~~~~~~~"
echo " M A I N - M E N U"
echo "~~~~~~~~~~~~~~~~~~~~~"
echo "1. User Confirmation"
echo "2. Simple Message"
echo "3. Handling Devices"
echo "4. Exit"
}
# read input from the keyboard and take a action
# invoke the user_confirm() when the user select 1 from the menu option.
# invoke the two() when the user select 2 from the menu option.
# Exit when user the user select 3 form the menu option.
read_options(){
local choice
read -p "Enter choice [ 1 - 3] " choice
case $choice in
1) user_confirm ;;
2) two ;;
3) pushover;;
3) exit 0;;
*) echo -e "${RED}Error...${STD}" && sleep 2
esac
}
# ----------------------------------------------
# Step #3: Trap CTRL+C, CTRL+Z and quit singles
# ----------------------------------------------
trap '' SIGINT SIGQUIT SIGTSTP
# -----------------------------------
# Step #4: Main logic - infinite loop
# ------------------------------------
while true
do
show_menus
read_options
done
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.