I am trying to create a very simple bash script with a GUI. I want it to bring up a dialog where the user can use the arrow keys to select a function, it will complete it and then return to the menu.

I started of using dialog as it will easy to list options but the script always ends once 1 action is complete.

Here is what I have so far :

dialog --menu "Task to perform" 10 30 3 1 This 2 That Office 3 Exit

Can anyone point me to the way of returning to the menu? (or another way!)


You don't need 3 Exit as an option as dialog already generates a "Cancel" button. You could do a loop to display the dialog box until the user presses the cancel button :

(Note: some of my code sample is taken from this answer)


#we start the loop....
while [[ "$dialog_exit" -ne 1 ]]; do
    #we force the redirection of the output to the file descriptor n°1 with the --fd-output 1 option
    dialog_result=$(dialog --clear --menu "Task to perform" 10 30 3 1 "This task" 2 "That task" 3 "Yet another task" --fd-output 1);

    #we store the exit code. If the user pressed cancel, exit code is 1. Else, it is 0.
    case "$dialog_result" in
        1) echo "task 1";;
        2) echo "task 2";;
        3) echo "task 3";;
        "") echo "action when cancel";;
  • Just tried to run your example, and I just get a flashing cursor. Any ideas? – user935227 Mar 16 '17 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.