The “whiptail” command is a Unix/Linux utility that allows shell scripts to display text-based dialog boxes for user interaction. It is commonly used to create interactive scripts that can prompt the user for input or display messages in a graphical format.
The “whiptail” command is based on the “dialog” command, which provides similar functionality but with a more traditional command-line interface. The advantage of “whiptail” is that it provides a more user-friendly interface that is easier to use and understand.
“Whiptail” can display a wide variety of dialog boxes, including message boxes, input boxes, password boxes, and menu boxes. These dialog boxes can be customized with different colors, fonts, and sizes to make them more visually appealing.
For example, a shell script could use “whiptail” to display a message box to the user when an error occurs, asking them to try again or exit the script. Or, it could use an input box to prompt the user for a password before performing a sensitive operation.
The “whiptail” command is particularly useful for creating simple and lightweight graphical interfaces for scripts, especially those that run on headless servers or in remote environments where a graphical user interface is not available. It can also be used to create menu-driven scripts that are easier for users to navigate and understand.
whiptail Command Examples
1. Display a simple message:
# whiptail --title "title" --msgbox "message" height_in_chars width_in_chars
2. Display a boolean choice, returning the result through the exit code:
# whiptail --title "title" --yesno "message" height_in_chars width_in_chars
3. Customise the text on the yes / no buttons:
# whiptail --title "title" --yes-button "text" --no-button "text" --yesno "message" height_in_chars width_in_chars
4. Display a text input box:
# result_variable_name="$(whiptail --title "title" --inputbox "message" height_in_chars width_in_chars default_text 3>&1 1>&2 2>&3)"
5. Display a password input box:
# result_variable_name="$(whiptail --title "title" --passwordbox "message" height_in_chars width_in_chars 3>&1 1>&2 2>&3)"
6. Display a multiple-choice menu:
# result_variable_name=$(whiptail --title "title" --menu "message" height_in_chars width_in_chars menu_display_height "value_1" "display_text_1" "value_n" "display_text_n" ..... 3>&1 1>&2 2>&3)
Summary
Overall, “whiptail” is a versatile and powerful utility that can greatly enhance the user experience of shell scripts by providing a simple and intuitive graphical interface.