Linux Format

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.

More from Linux Format

Linux Format10 min read
Answers
I was originally using the Cinnamon version of Linux Mint 21.3. I heard good things about MATE, so I did a new installation to try out MATE. After several months, I decided that I would like to go back to Cinnamon. I am not sure how to switch back wi
Linux Format2 min read
Suitability For Beginners
These distros are focused on a technical area of computer use, penetration testing, but that doesn’t mean they’re T not suitable for beginners in this discipline. It’s not much of a surprise that a Gentoo-based distro like Pentoo is more complicated
Linux Format11 min read
Enhance Email With A Better Thunderbird
Think email client and the obvious example is Mozilla’s Thunderbird. But whether you’re a T long-time Thunderbird user or looking for a new email client, you may find that Betterbird is – if you’ll excuse the pun – a better fit. That’s particularly t

Related