You can easily master shell scripting in just 10 seconds!!
Dialog supports 8 types of GUI controls namely -
- Menu boxes
- Input boxes
- Message boxes
- Radio lists
- Text boxes
- Checklist boxes
- Info boxes, and
- Yes / No boxes.
Creating a dialog is very easy. The following examples will throw light on its usage.
Input boxes allow the user to enter a string. After the user enters the data, it is written to standard error . You may also redirect the output to a file.
$ dialog --title "Ravi's Input Box" --inputbox "Enter the parameters..." 8 40
As you can see, the options are self explanatory. The last two options 8 and 40 are the height and width of the box respectively.
And this is how the resulting input box looks on your terminal.
A text box takes a file as the parameter and shows the file in a scrollable box.
$ dialog --title "textbox" --textbox ./myfile.txt 22 70
... it shows the file
myfile.txtin a textbox.
A checklist presents the user with a list of choices. The choices can be toggled ON or OFF individually using the space bar.
$ dialog --checklist "Choose your favorite distribution:" 10 40 3 1 RedHat on 2 "Ubuntu Linux" off 3 Slackware off
In the Dialog command shown above, 10 is the height of the box, 40 - width, 3 is the number of choices, and the rest are the choices numbered 1,2 and 3.
A radio list displays a list containing radio buttons. The user can choose only a single option from the set of options.
$ dialog --backtitle "Processor Selection" --radiolist "Select Processor type:" 10 40 4 1 Pentium off 2 Athlon on 3 Celeron off 4 Cyrix off
10 and 40 are the height and width respectively. 4 denotes the number of items in the list, followed by the items.
An info box is useful for displaying a message while an operation is going on. As an example, see the code below:
$ dialog --title "Memory Results" --infobox "`echo ;vmstat;echo ;echo ;free`" 15 85
And the following is a message box.
% dialog --title "Message" --msgbox "You are PROHIBITED from rebooting your machine!!" 8 30
Fig: Message box
Dialog is usually used inside a script which gives the script a degree of user friendliness.
There is another package called Xdialog which gives the same features for scripts executed in X Windows. Xdialog utility also has additional functionality not found in the dialog utility.
To know more in using the Dialog command line tool in Linux, check its manpage.