3

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!)

Aserre
  • 1,177
  • 12
  • 18

1 Answers1

1

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)

#!/bin/bash

#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.
    dialog_exit=$?;
    case "$dialog_result" in
        1) echo "task 1";;
        2) echo "task 2";;
        3) echo "task 3";;
        "") echo "action when cancel";;
    esac
done
Aserre
  • 1,177
  • 12
  • 18