linux - Creating a Menu Script -


i trying create menu script execute command when option selected. have far.

#!/bin/bash  ps3='please enter choice: ' options=("option 1 - file directory?" "option 2 - run myscript?" "option 3 - ?" "4 - quit") select opt in "${options[@]}"        case $opt in             "option 1 - file directory?")                 echo "you chose option 1"                 ;;             "option 2 - run myscript?")                 echo "you chose option 2"                 ;;             "option 3 - ?")                 echo "you chose option 3"                 ;;             "quit")                 break                 ;;             *) echo invalid option;;          esac done  

change select select , "quit" "4 - quit" inside case or otherwise.

your code edited:

ps3='please enter choice: ' options=("file directory?" "run myscript?" "?" "quit") select opt in "${options[@]}"        case $opt in             "file directory?")                 echo "you chose option 1"                 ;;             "run myscript?")                 echo "you chose option 2"                 ;;             "?")                 echo "you chose option 3"                 ;;             "quit")                 break                 ;;             *) echo invalid option;;          esac done  

you can check errors in shell script with shellcheck.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -