Bash Shell Scripting/Whiptail

Whiptail is a program that allows shell scripts to display dialog boxes to the user for informational purposes, or to get input from the user in a friendly way. Whiptail is included by default on Debian.
 * From the Linux Dictionary: whiptail is a "dialog" replacement using newt instead of ncurses.
 * From its README: whiptail is designed to be drop-in compatible with dialog(1), but has fewer features: some dialog boxes are not implemented, such as tailbox, timebox, calendarbox, etc.

Try using dialog to replace whiptail if you don't have whiptail: alias whiptail='dialog'

Note that there are also other dialog-compatible programs like xdialog (Displays X11 Windows) and zenity (aka gdialog, displays Gtk Windows). Reading dialog's manual page should be helpful. Always read the man pages or  so you know in which way they're different from dialog.

Info box
A simple type of dialog box in Whiptail is the info box. This shows a dialog box containing text to the user.

In the example above, the value of --title is displayed at the top of the dialog box. The first argument to --infobox is the dialog box text which is shown beneath the title. The next two arguments specify the height and width of the dialog box. The width is set to 78 as most terminals will be at least 80 columns or more.

There is a bug that makes the Info Box not display on some shells. If this is the case you can set the terminal emulation to something different and it will work.

Message box
A message box is very similar to an info box, except that it waits for the user to hit the OK button. Usage is similar to the info box:



Yes/no box
The simplest way to get input from the user is via a Yes/no box. This displays a dialog with two buttons labelled Yes and No.



Input box
A way to get free-form input from the user is via an input box. This displays a dialog with two buttons labelled Ok and Cancel.



Text box
A text box with contents of the given file inside. Add --scrolltext if the filename is longer than the window.



Password box
A way to get a hidden password from the user is via a password box. This displays a dialog with two buttons labelled Ok and Cancel.



Menus
Whenever you want to present a list of options to the user, whiptail has several dialog types to choose from.

A menu should be used when you want the user to select one option from a list, such as for navigating a program.



The values given to --menu are:
 * The text describing the menu ("Choose an option")
 * The height of the dialog (25)
 * The width of the dialog (<tt>78</tt>)
 * The height of the menu list (<tt>16</tt>)

The rest of the values are a list of menu options in the format <tt>tag item</tt>, where <tt>tag</tt> is the name of the option which is printed to <tt>stderr</tt> when selected, and <tt>item</tt> is the description of the menu option.

If you are presenting a very long menu and want to make best use of the available screen, you can calculate the best box size by.



Check list
At some point, you will want to present options to the user which would not be appropriate to place in a menu.

A check list allows a user to select one or more options from a list.

When the user confirms their selections, a list of the choices is printed to <tt>stderr</tt>.

Radio list
A radio list is a dialog where the user can select one option from a list. The difference between a radio list and a menu is that the user selects an option (using the space bar in whiptail) and then confirms that choice by hitting OK.



Progress gauge
Syntax: <tt>whiptail --gauge  [ ]</tt>

Also reads <tt>percent</tt> from stdin: