How to display dialogs in Bash Shell scripts

  
 

This tutorial gives examples of how to provide messages/dialogs in Bash Shell scripts using tools like zenity and whiptail. Using these tools, your script can tell the user what the current program is doing and interact with the user. The difference between these two tools is the way the message box or dialog is displayed. Zenity creates a graphical user interface with the GTK toolkit, while whiptail creates a message box within the terminal window.

Zenity Tools

Installing zenity in Ubuntu, run:

sudo apt-get install zenity

The command to create a message box or dialog with zenity is self-explanatory We will give you some examples for reference.

Create a message box

zenity --info --title "Information Box" --text "This should be information" --width=300 --height=200


Create a Yes/No query dialog

zenity --question --text "Do you want this?" --ok-label "Yeah" --cancel-label= "Nope"


Create an input box and save the input values ​​to a variable

a=$(zenity --entry --title "Entry box" --text " ;Please enter the value" --width=300 --height=200)echo $a


When entered, the value is stored in the variable $a.

This is a real example of getting a user's name and displaying it.

#!/bin/bash## This script will ask for couple of parameters# and then continue to work depending on entered values## Giving the option to userzenity --question --text "Do you want To continue?"# Checking if user wants to proceed[ $? -eq 0 ] 
						
Copyright © Windows knowledge All Rights Reserved