Press "Enter" to skip to content

Linux Dialog Examples

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.

WidgetDescriptionParameters
calendarProvides a calendar from which to select a date<text> <height> <width> <day> <month> <year>
checklistDisplays multiple entries where each entry can be turned on or off<text> <height> <width> <list height> <tag1> <item1> <status1>
formAllows 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>
fselectProvides a fi le selection window to browse for a fi le<filepath> <height> <width>
gaugeDisplays a meter showing a percentage of completion<text> <height> <width> [<percent>]
infoboxDisplays a message without waiting for a response<text> <height> <width>
inputboxDisplays a single text form box for text entry<text> <height> <width> [<init>]
inputmenuProvides an editable menu<text> <height> <width> <menu height> <tag1> <item1>
menuDisplays a list of selections from which to choose<text> <height> <width> <menu height> <tag1> <item1>
msgboxDisplays a message and requires the user to select an OK button<text> <height> <width>
pauseDisplays a meter showing the status of a specifi ed pause period<text> <height> <width> <seconds>
passwordboxDisplays a single textbox that hides entered text<text> <height> <width> [<init>]
passwordformDisplays 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>
radiolistProvides a group of menu items where only one item can be selected<text> <height> <width> <list height> <tag1> <item1> <status1>
tailboxDisplays text from a fi le in a scroll window using the tail command<file> <height> <width>
tailboxbgSame as tailbox but operates in background mode<file> <height> <width>
textboxDisplays the contents of a fi le in a scroll window<file> <height> <width>
timeboxProvides a window to select an hour minute and second<text> <height> <width> <hour> <minute> <second>
yesnoProvides 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:

  1. STDERR
  2. 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

Linux dialog input widget.

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

Linux msgbox dialog widget.

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

yesno widget.

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

Dialog fselect widget.

See the contents of the file.txt:

cat file.txt

Output

./callpy.sh

Vinish Kapoor

Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. foxinfotech.in is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Comments are closed.