Shell Scripting - Dialog Boxes
Last Updated :
10 Nov, 2022
In this article, we will create a shell script that generates a Dialog Box with GUI generating a message to the user.
What is a Dialog Box?
A Dialog Box is a temporary window an application runs to convey important information to the users. These dialog boxes can be used to display warnings, errors, and also any additional inputs needed by the system from End Users.
Installation Of Dialog Utility In Linux :
Dialog utility: Dialog Utility is used to create a Graphical User Interface-based Dialog Box that can be used to get any important information from the users.
Modules Needed To Be Installed :
For Ubuntu and Debian Linux
sudo apt-get update
sudo apt-get install 1 dialog
For CentOS or Redhat Linux :
sudo yum install dialog
Now, Let us run Bash Scripts to create Dialog Boxes, please do note that we are using an ubuntu-based Linux VM, but you can try this on any Linux Distribution but please follow the above-mentioned commands for respective distribution to download modules.
1. Shell Script to create Dialog Box to Greet Users :
In this, let's create a shell script that generates a greeting to users.
Shell Script :
#!/bin/bash
function DialogGen() {
dialog --title "Hello" --msgbox 'Hello GFG Users!' 6 20
}
DialogGen
Output :

- In Above Shell Script we generated a Dialog Box on a Ubuntu Machine that Greeted users using the DialogGen function. It displayed a message box greeting "Hello GFG Users" with an ok button.
- We can use this dialog box to display any message of our choice.
- Users can click on the ok button and the dialog box exits and the calling shell script continues its operation.
- After exiting, there will be no text written on dialog's output but an ESC type exit status will be returned.
Understanding options Involved in Dialog Box
Now, In the above-created dialog Box let us debug the options used for getting a better understanding of how Dialog Boxes function on a Linux Environment.
- --title "Hello": This sets a title string that gets displayed at the beginning of the dialog box which acts as the title for created Dialog Box.
- --msgbox 'Hello GFG Users !': This displays a message "Hello" to users, you can customize what you want to greet end-users.
- 6: value for Height of msgbox box.
- 20: Value of width of msgbox box.
Now, let's go through various widgets that can be created using the Dialog tool using shell scripts.
2. Shell Script to display Dialog Box with Calendar :
Syntax :
-checklist <text> <height> <width> <list height> <tag1> <item1> <status1>…
messg.sh :
#!/bin/bash
function DialogGen
{
dialog --calendar "calendar" 5 50 12 02 2022
}
DialogGen
Output :

Understanding options used in the above dialog box :
- --calendar: This Keyword is used to display the title of the Dialog Box.
- --5 50 12 02 2022 : 5 is value for Height 50 is for width, 12 02 2022 is today's date.
3. Shell Script to generate Dialog Box for displaying checklist widget.
Let's create a shell script that generated a checklist of fruits and vegetables :
messg.sh :
#!/bin/bash
function DialogGen ()
{
dialog --checklist 'checklist' 15 10 10 'potato' 5 'on' 'carrot' 2 'off' 'grape' 3 'on' 'cabbage; 4 'off'
}
DialogGen
Output :

Understanding options used in the above dialog box :
- --Checklist "checklist": Checklist keyword initiates checklist followed by text that used as the title of the Dialog Box.
- --15 10 10: 15 in height followed by 10 value set for width and 10 used as the value set for list height.
- --'potato' 5 'on': here potato is item1 is potato followed by 5 set as tag value and on is the status for checklist box(it is either on or off).
4. Shell Script to create a msgbox using dialog tool :
Let's try to create a msgbox that displays a text message to users on a Linux Machine.
Syntax :
--msgbox <text> <height> <width>
messg.sh :
#!/bin/bash
function DialogGen () {
--msgbox "Hi geeks, hope everyone are enjoying GeeksForGeeks" 10 30
}
DialogGen
Output :

Understanding options used in the above Dialog Box :
- -msgbox : This keyword initiates the msgbox dialog Box on the shell console.
- -text: This text includes messages we want to convey to end-users.
- -10 : this is the value set for Height.
- -30 : value set for width.
5. Shell Script to generate Gauge Dialog Box :
Let us generate a shell script function that displays the Gauge type of Dialog Box on the shell console.
Syntax :
--gauge <text> <height> <width> [<percent>]
messg.sh :
#!/bin/bash
function DialogGen
{
--gauge "in progress..." 10 20 40
}
DialogGen
Output :

6. Shell Script to generate Form Dialog Box :
let us generate a shell script function that displays a form on the console shell.
Syntax :
--form <text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1> …
messg.sh :
function DialogGen () {
dialog --form "please enter the required information" 12 40 4 "Name:" 1 1 "" 1 12 15 0 \ "Age:" 2 1 "" 2 12 15 0 "Mail id:" 3 1 "" 3 12 15 0
}
DialogGen
Output :

7. Shell Script to generate infobox Dialog Box on Linux Machine :
In this, let us generate a Shell Script function that runs the infobox dialog box.
Syntax :
--infobox <text> <height> <width>
messg.sh :
#!/bin/bash
function DialogGen () {
dialog --infobox "Geeks, this is just a sample message" 10 31
}
DialogGen
Output :

8. Shell Script to generate inputbox dialog box on a Linux machine :
In this, we try to generate a Shell Script function that runs an input box type dialog Box.
Syntax :
--inputbox <text> <height> <width> [<init>]
messg.sh :
#!/bin/bash
function DialogGen() {
dialog --inputbox "geeks, please enter your name" 10 31 "enter here"
}
DialogGen
Output :

9. Shell Script to generate InputMenu Dialog Box
Now, let us write a shell script function to generate InputMenu Dialog Box on a Linux Machine.
Syntax :
--inputmenu <text> <height> <width> <menu height> <tag1> <item1>…
messg.sh :
#!/bin/bash
function DialogGen() {
dialog --inputmenu "Edit if required," 12 45 25 1 "hi" 2 "good morning" 3 "Take" "Care"
}
DialogGen
Output :

10. Shell Script to generate Menu from Dialog Box :
In this script, we try to create a Shell Script Function that runs Menu Widget Dialog Box.
Syntax :
--menu <text> <height> <width> <menu height> <tag1> <item1>…
messg.sh :
#!/bin/bash
function DialogGen() {
dialog--menu "choose your favourite fruit" 12 45 25 1 "apple" 2 "banana" 3 "grapes" 4 "oranges"
}
DialogGen
Output :

11. Shell Script to create Yes/No Box :
In this Script, we generate a function that displays Dialog Box GUI with a yes or no option to users.
Syntax :
-yesno <text> <height> <width>
Script :
messg.sh :
#!/bin/bash
function DialogGen() {
dialog --yesno "Hey Geek, Do You Want To Continue With Current Session?" 10 31
}
DialogGen
Output :

12. Shell Script to design a Password Box :
In this script our job is to generate a function that displays, a password form with hidden Text fields.
Syntax :
--passwordform <text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1>…
Script :
messg.sh :
#!/bin/bash
function DialogGen() {
dialog --passwordform "Hey Geek, please enter required information:" 12 40 4 "password:" 1 1 "" 1 12 15 0 "otp:" 2 1 "" 2 12 15 0 "secret key:" 3 1 "" 3 12 15 0
}
DialogGen
Output :

13. Shell Script to display Radio Box Dialogue :
In this, let's run a function in a shell script that generates Radio Box Dialogue on a Linux Machine :
Syntax :
--radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>…
Script :
#/bin/bash
function DialogGen() {
dialog --radiolist 'radiolist' 15 10 10 'Grapes' 5 'off' 'apple' 2 'off' 'dessert' 3 'off' 'coffee' 4 'on'
}
DialogGen
Output :

Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
Linux Commands Cheat Sheet Linux, often associated with being a complex operating system primarily used by developers, may not necessarily fit that description entirely. While it can initially appear challenging for beginners, once you immerse yourself in the Linux world, you may find it difficult to return to your previous W
13 min read
CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi
6 min read
What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read
Linux/Unix Tutorial Linux is one of the most widely used open-source operating systems. It's fast, secure, stable, and powers everything from smartphones and servers to cloud platforms and IoT devices. Linux is especially popular among developers, system administrators, and DevOps professionals.Linux is:A Unix-like OS
10 min read