Whiptail is a newt-based utility allowing to build pseudo-graphical dialog boxes from shell scripts. Dialog uses ncurses and is similar to whiptail but has more options and, consequently, a bit harder to use. I find both useful when a user needs to be guided through a complex set of variables and to minimize fat-fingering.

The best to understand how to use dialog and whiptail (and sometimes you would want to use both of them in the same script) is by looking at some example. In this first example we’re prompting the user for database connection information to build the ${MYSQL} connection string:

The next example connects to the database to populate a whiptail radio checklist with the names of available schemas. The second function connects to the selected database to get a list of tables and build another radio checklist. This is a good example of how to build dynamic menus.

The whiptail utility has an unfortunate limitation: it can only ask you one question at a time. This can get tedious and distracting. The following example uses dialog to present you with three questions and set variables var1 through var3. The dialog can’t assign each response to an individual variable. You would need to parse the output as illustrated below.

And a few simple whiptail dialog boxes that may come in handy in many scripts. This is a simple yes/no dialog:

Here’s a simple message box. For some visual interest I added output of an array containing output of the ps command:

This is another message box designed to hold a bit more content:

Leave A Reply

Please enter your comment!
Please enter your name here