Previously I have given some examples of dialog package in Linux to create a menu, password boxes, and the progress bar. In this tutorial, I am giving some more details of Linux dialog package widgets with their examples.
Note: The dialog package isn't installed in all Linux distributions. For Ubuntu Linux, the following is the command to install it.
sudo apt-get install dialog
List of Linux Dialog Package Widgets
You can pass the following widgets as the parameter to dialog command to use it.
Widget | Description | Parameters |
---|---|---|
calendar | Provides a calendar from which to select a date | <text> <height> <width> <day> <month> <year> |
checklist | Displays multiple entries where each entry can be turned on or off | <text> <height> <width> <list height> <tag1> <item1> <status1> |
form | Allows you to build a form with labels and text fi elds to be fi lled out | <text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1> |
fselect | Provides a fi le selection window to browse for a fi le | <filepath> <height> <width> |
gauge | Displays a meter showing a percentage of completion | <text> <height> <width> [<percent>] |
infobox | Displays a message without waiting for a response | <text> <height> <width> |
inputbox | Displays a single text form box for text entry | <text> <height> <width> [<init>] |
inputmenu | Provides an editable menu | <text> <height> <width> <menu height> <tag1> <item1> |
menu | Displays a list of selections from which to choose | <text> <height> <width> <menu height> <tag1> <item1> |
msgbox | Displays a message and requires the user to select an OK button | <text> <height> <width> |
pause | Displays a meter showing the status of a specifi ed pause period | <text> <height> <width> <seconds> |
passwordbox | Displays a single textbox that hides entered text | <text> <height> <width> [<init>] |
passwordform | Displays a form with labels and hidden text fi elds | <text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1> |
radiolist | Provides a group of menu items where only one item can be selected | <text> <height> <width> <list height> <tag1> <item1> <status1> |
tailbox | Displays text from a fi le in a scroll window using the tail command | <file> <height> <width> |
tailboxbg | Same as tailbox but operates in background mode | <file> <height> <width> |
textbox | Displays the contents of a fi le in a scroll window | <file> <height> <width> |
timebox | Provides a window to select an hour minute and second | <text> <height> <width> <hour> <minute> <second> |
yesno | Provides a simple message with Yes and No buttons | <text> <height> <width> |
Syntax of Dialog Command
The following is the syntax to use a specific widget with dialog command.
dialog --widget parameters
The dialog widget provides its output in two ways:
- STDERR
- Exit code status
If the user selects an OK button, then dialog command returns a 0 exit status, and if the user selects the Cancel button or selects no button, then it returns the 1 exit status.
If the dialog widget returns any data such as user input value or the menu selection, the dialog command sends the output to the STDERR. You can use redirect the output to a file or the file descriptor. For example:
Dialog inputbox Widget
dialog --inputbox "Enter your name:" 10 40 2>name.txt
Output
If you check the file name.txt, then you will find the input content in the file.
msgbox Widget Example
dialog --title Information[!] --msgbox "This is an information message." 10 50
Output
yesno Widget Example
The following yesno widget will ask the confirmation to delete a file.
dialog --title "Confirmation" --yesno "Are you sure to delete this file?" 10 40
Output
To check the user selection by checking the exit status with $? command. For example:
echo $?
var=$?
fselect Widget Example
The following command will give an option to user to select a file from the current directory.
dialog --title "Browse" --fselect ./ 12 50 2>file.txt
Output
See the contents of the file.txt:
cat file.txt
Output
./callpy.sh