Scripting text-based checklists in Bash
We’re going to focus on coding a checklist, as a component like this lets a user select multiple choices, a single item, or none at all, which makes it quite a versatile little input mechanism. The four variants use commands that offer increasingly sophisticated-looking dialog boxes, ranging from pure text up to fancy GUIs.
All the checklists are wrapped inside different versions of a function called getOptions(). It takes an array of strings as input, that become the checklist’s choices, and returns a count of the selected items, and then stores the indices of those choices in a global array called opts. A black-box diagram of getOptions()’s inputs and outputs is shown in Figure 1.
The four versions of getOptions() are coded using the select, dialog, zenity and yad commands. Select is a build-in that generates a text-based menu of choices. Dialog supports a wide range of TUI (text-based user interface) components rendered using the ncurses library, including a checklist. The rise of GUI desktops in the 1990s led to the appearance of window-based versions of dialog, with zenity perhaps being the more popular. Yad is a zenity fork with many additional dialogs such as a versatile form component.
You’re reading a preview, subscribe to read more.
Start your free 30 days