I am a beginner to script. I am making a tool script for my theme with 2 functions: Check for update, reinstall themeSo here is the code for selection menu:PS3='Choose an option: 'options=(Check for update Reinstall theme)select opt in ${options[@]}do     case $opt in             Check for update)                       echo Checking update                               ;;             Reinstall theme)                       echo Reinstalling                               ;;                               *) echo invalid option;;     esacdoneWhen running it appear like this1) Check for update2) Reinstall themeChoose an option:I type 1 and enter, the check for update command is performedThe problem is when it finished performing the script, it re-display Choose an option: not with the menu. So it can make users hard to choose without the menu (especially after a long script)1) Check for update2) Reinstall themeChoose an option: 1Checking updateChoose an option:So how can I re-display the menu after an option is performed
bash - How can I re-display selection menu after a selection is chosen and performed
bash;select
I'm guessing you really want something like this:function check_update {        echo Checking update}function reinstall_theme {        echo Reinstalling theme}all_done=0while (( !all_done )); do        options=(Check for update Reinstall theme)        echo Choose an option:        select opt in ${options[@]}; do                case $REPLY in                        1) check_update; break ;;                        2) reinstall_theme; break ;;                        *) echo What's that? ;;                esac        done        echo Doing other things...        echo Are we done?        select opt in Yes No; do                case $REPLY in                        1) all_done=1; break ;;                        2) break ;;                        *) echo Look, it's a simple question... ;;                esac        donedoneI've separated out the tasks into separate function to keep the first case statement smaller. I've also used $REPLY rather than the option string in the case statements since this is shorter and won't break if you decide to change them but forget to update them in both places. I'm also choosing to not touch PS3 as that may affect later select calls in the script. If I wanted a different prompt, I would set it once in and leave it (maybe PS3=Your choice: ). This would give a script with multiple questions a more uniform feel.I've added an outer loop that iterates over everything until the user is done. You need this loop to re-display the question in the first select statement.I've added break to the case statements, otherwise there's no way to exit other than interrupting the script.The purpose of a select is to get an answer to one question from the user, not really to be the main event-loop of a script (by itself). In general, a select-case should really only set a variable or call a function and then carry on. A shorter version that incorporates a Quit option in the first select:function check_update {    echo Checking update}function reinstall_theme {    echo Reinstalling theme}all_done=0while (( !all_done )); do    options=(Check for update Reinstall theme Quit)    echo Choose an option:     select opt in ${options[@]}; do        case $REPLY in            1) check_update; break ;;            2) reinstall_theme; break ;;            3) all_done=1; break ;;            *) echo What's that? ;;        esac    donedoneecho Bye bye!