Dialog: An Introductory Tutorial
Linux is based on the Unix operating system, but also features a number of unique and useful kernel features and application programs that often go beyond what is available under Unix. One little-known gem is “dialog”, a utility for creating professional-looking dialog boxes from within shell scripts. This article presents a tutorial introduction to the dialog utility, and shows examples of how and where it can be used.
by Jeff Tranter
If you have installed a recent version of the Slackware Linux distribution, you've seen the professional-looking install process; it was created using the dialog utility.
True to the Unix tradition of writing general-purpose tools that work together, dialog allows creating text-based color dialog boxes from any shell script language. It supports eight types of dialogs:
yes/no boxes
menu boxes
input boxes
message boxes
text boxes
info boxes
checklist boxes
radiolist boxes
Dialog is very easy to use. If you've got your keyboard handy, here's a one-line example of a message box you can try. (Note: The examples in this article assume you are running a Bourne-compatible shell program such as GNU bash.)
% dialog --title 'Message' --msgbox 'Hello, world!' 5 20
This example creates a message box with the title “Message”, containing the greeting “Hello, world!”. The box is 5 lines high and 20 characters wide, with the message nicely centered in the box. An “OK” button appears at the bottom; pressing <enter> dismisses the menu.
Most calls to dialog are in a similar format: an optional title, the dialog type, the text to be displayed, and the height and width (in characters) of the dialog box. Additional parameters specific to each menu type follow. Let's have a brief look at each of the available types.
The “yesno” menu is very similar to our first example:
% dialog --title "Message" --yesno "Are you having\ fun?" 6 25
If you try this example, you will see that there are now two buttons at the bottom, labeled “Yes” and “No”. You can select between the buttons using the cursor keys (or <tab>) and make your selection by pressing <enter>. The exit status returned to the shell will be 0 if “Yes” is chosen and 1 if a “No” selection is made.
You may wish to try experimenting with the height and width parameters. If the width is less than the string length, the string is wrapped around (at word boundaries). If you make the dialog box too small, then characters will be lost.
We previously saw the message box. The “infobox” is similar except that it does not wait for the user to select an “OK” button. This is useful for displaying a message while an operation is going on. Here is an example:
% dialog --infobox "Please wait" 10 30 ; sleep 4
The “inputbox” allows a user to enter a string. The usual editing keys can be used, and the text field scrolls if necessary. After the user enters the data, it is written to standard error (or more commonly redirected to a file as in this example):
% dialog --inputbox "Enter your name:" 8 40 2>answer
The “textbox” type is a simple file viewer; it takes a filename as a parameter:
% dialog --textbox /etc/profile 22 70
The usual movement keys work here: the cursor keys, Page Up, Page Down, Home, etc. You can exit by pressing <esc> or <enter>.
The “menu” type allows creating a menu of choices from which the user can choose. The format is
% dialog --menu <text> <height> <width> <menu-height> [<tag><item>]
Each menu entry consists of a “tag” string and an associated “item” string, both of which are displayed. The user can make a choice using the cursor keys and pressing <enter>. The selected tag is written to standard error. Here is a simple example:
% dialog --menu "Choose one:" 10 30 3 1 red 2 green\ 3 blue
The next type is the “checklist”. The user is presented with a list of choices and can toggle each one on or off individually using the space bar:
% dialog --checklist "Choose toppings:" 10 40 3 \
1 Cheese on \
2 "Tomato Sauce" on \
3 Anchovies off
The third field in each choice is the initial state; -either “on” or “off”. The last type is the “radiolist”, essentially the same as the checklist except that the user must make one choice from a list of mutually exclusive options. The radiolist type, and the alternate form of title show here, were introduced in version 0.4 of dialog.
% dialog --backtitle "CPU Selection" \
--radiolist "Select CPU type:" 10 40 4 \
1 386SX off \
2 386DX on \
3 486SX off \
4 486DX off
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- New Products
- Linux Systems Administrator
- Web & UI Developer (JavaScript & j Query)
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Large-Scale Mail with Postfix, OpenLDAP and Courier
- Open-Source Learning Management with Moodle
- Using an SMS Server to Provide a Robust Alerting Service for Nagios
- The ELF Object File Format by Dissection
- Reply to comment | Linux Journal
8 hours 19 min ago - Nice article, thanks for the
19 hours 5 sec ago - I once had a better way I
1 day 46 min ago - Not only you I too assumed
1 day 1 hour ago - another very interesting
1 day 2 hours ago - Reply to comment | Linux Journal
1 day 4 hours ago - Reply to comment | Linux Journal
1 day 11 hours ago - Reply to comment | Linux Journal
1 day 12 hours ago - Favorite (and easily brute-forced) pw's
1 day 13 hours ago - Have you tried Boxen? It's a
1 day 19 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




Comments
Dialog Not displaying correctly
Hi Guys,
I'm writing an application using dialog for a production machine that does not have any window managers or desktops installed. My development environment has a gnome desktop and the terminal window seems to display dialogs correctly, but when I copy the script to the production environment, the display is misaligned and does not look as neat as what I see in the development environment.
I've tested the application on the production machine in a telnet session from my development machine, and then it displays correctly, so I can only assume that something is wrong with the terminal settings on the actual production environment.
Both operating systems are exactly the same. Do I need to change any terminal settings or configurations to make the dialogs display correctly?
Thanks
using dialog in Red hat Linux or SUSE linux
How do i use the dialog facility on Red Hat Linux and/or SUSe Linux. can you give a link where one can download the package
Standard Package Manger
You should be able to find them in the standard repositories using the standard package managers. On SuSE use zypper (or yast). On Red Hat use yum. From a shell prompt do:
Mitch Frazier is an Associate Editor for Linux Journal.
corrections
The lines:
dialog --title "Message" --yesno "Are you having\ fun?" 6 25
dialog --menu "Choose one:" 10 30 3 1 red 2 green\ 3 blue
should read:
dialog --title "Message" --yesno "Are you having fun?" 6 25
dialog --menu "Choose one:" 10 30 3 1 red 2 green 3 blue
the backslash is only needed to escape a new-line character for commands written over multiple shell command-lines. There are other occurences of this type of error in the article. This may have occured because of the web content software used on this site causing lines to be concatenated.
Check out the `Xdialog` package (http://xdialog.dyns.net/), which is a drop-in replacement for `dialog`, but does the same thing for an X Window GUI environment. Also, newer versions of `dialog` are sometimes referred to as `cdialog` (http://freshmeat.net/projects/cdialog/).
HTH.