Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ How to display a dialog Bash Shell script     - Python programmers most often committed ten errors (Programming)

- CentOS 6.6 command-line automatic completion (Linux)

- Java MD5 encryption implementation (Programming)

- Ubuntu download install and configure Plank Dock (Linux)

- Apache Kafka: the next generation of distributed messaging system (Server)

- Linux use glibc2 library and crypt () function to generate the user password (Programming)

- Java thread pool: ExecutorService, Executors (Programming)

- Linux / proc directory Comments (Linux)

- Android LayoutInflater source parsing (Programming)

- How to deploy Icinga server (Server)

- Varnish configuration language VCL and its built-in variables (Server)

- Gentoo: startx appeared Failed to load module Problem Solving (Linux)

- C ++ multithreading and critical resource instance (Programming)

- Hardware Firewall Basics (Linux)

- How to migrate MySQL to MariaDB under linux (Database)

- Install MATE desktop environment adjustment tools Mate Tweak 3.3.6 (Linux)

- A new method for Linux hidden files (Linux)

- OpenSSH version smooth upgrade method (Linux)

- Solve ORA-01012: not logged on (Database)

- OpenSSL Introduction and compilation steps on Windows, Linux, Mac systems (Linux)

 
         
  How to display a dialog Bash Shell script
     
  Add Date : 2018-11-21      
         
         
         
  This tool gives tutorial on how to use several similar zenity whiptail and to provide information / examples of dialog in Bash Shell script. Using these tools, you can inform the user of the script is currently running a state and can interact with the user. The difference between these two tools is the way the message box or dialog box is displayed. Zenity with GTK toolkit for creating graphical user interfaces, and whiptail message box is created in the terminal window.

Zenity tool

Zenity installed in Ubuntu, run:

sudo apt-get install zenity
Create a message box or dialog with zenity command is not self-evident, 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 dialog asking

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

Save the created input box and enter a value to a variable

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

Once entered, the value stored in the variable $ a in.

This is a practical example to obtain the user name and displayed.

#! / Bin / bash
#
# This script will ask for couple of parameters
# And then continue to work depending on entered values
#
# Giving the option to user
zenity --question --text "Do you want to continue?"
# Checking if user wants to proceed
[$ -? Eq 0] || exit1
# Letting user input some values
FIRSTNAME = $ (zenity --entry --title "Entry box" - text "Please, enter your first name." - Width = 300 - height = 150)
LASTNAME = $ (zenity --entry --title "Entry box" - text "Please, enter your last name." - Width = 300 - height = 150)
AGE = $ (zenity --entry --title "Entry box" - text "Please, enter your age." - Width = 300 - height = 150)
# Displaying entered values in information box
zenity --info --title "Information" - text "You are $ {FIRSTNAME} $ {LASTNAME} and you are $ {AGE} (s) old." - width = 300 - height = 100

Whiptail tool

Whiptail installed on Ubuntu, run

sudo apt-get install whiptail
Create a message box with the command whiptail or dialog is self-explanatory, we will provide you with some basic examples as a reference.

Create a message box

whiptail --msgbox "This is a message" 1040

Create a Yes / No dialog

whiptail --yes-button "Yeah" - no-button "Nope" - title "Choose the answer" - yesno "Will you choose yes?" 1030

Create an input box defaults

whiptail --inputbox "Enter your number please." 1030 "10"

Try using the input value point to note is whiptail with stdout displays a dialog box with the stderr output value. In this case, if you use the var = $ (...), you will not see the dialog box, enter a value can not be obtained. The solution is to swap stdout and stderr. In whiptail command to add back 3> & 1 1> & 2 2> & 3 can be done. You want to get the input value of any whiptail command as well.

Create Menu dialog box

whiptail --menu "This is a menu Choose an option:." 2050101 "first" 2 "second" 3 "third"

This is a request for the user to enter a path to the output folder and its size shell script.

#! / Bin / bash
#
#
# Since whiptail has to use stdout to display dialog, entered value will
# Be stored in stderr. To switch them and get the value to stdout you must
# Use 3> & 1 1> & 2 2> & 3
FOLDER_PATH = $ (whiptail --title "Get the size of folder" \
--inputbox "Enter folder path:" \
1030 \
"/ Home" \
3> & 11> & 22> & 3)
if [-d $ FOLDER_PATH]
then
size = $ (du -hs "$ FOLDER_PATH" | awk '{print $ 1}')
whiptail --title "Information" \
--msgbox "Size of $ {FOLDER_PATH} is $ {size}" \
1040
elif [-f $ FOLDER_PATH]
then
whiptail --title "Warning !!!" \
--msgbox "The path you entered is a path to a file not a folder!" \
1040
else
whiptail --title "Error !!!"
--msgbox "Path you entered is not recognized. Please try again" \
1040
fi

in conclusion

Select the appropriate tool displays a dialog box depends on what you expect to run your scripts on your desktop machine or server. A desktop machine users typically use GUI windowing environment, you may run the script with the window that appears to interact. However, if you expect users are working on the server, (in the absence of a graphical interface), you may want to ensure that the total energy display, then use whiptail or any other tool dialog box is displayed in plain terminal window.
     
         
         
         
  More:      
 
- Nginx installation configuration Zabbix (Server)
- UUID in Java (Programming)
- C # get the current screenshot (Programming)
- Build a Linux development environment under STC89C52RC (Linux)
- Android judgment toward camera pictures (Programming)
- Linux server is how to do after the invasion (Linux)
- Repair after installing Ubuntu no boot device error (Linux)
- List Leaves (Programming)
- Linux redirection and piping (Linux)
- Design and implementation of environment sniffer running under Linux (Linux)
- Linux System Getting Started Tutorial: How to Force Change your password at next logon Linux (Linux)
- Let the terminal under Mac OS X as like Linux has displayed a variety of colors (Linux)
- CentOS permanently banned from running in the background PackageKit (Linux)
- command-line tool for send e-mail (Linux)
- bash login and welcome message: / etc / issue, / etc / motd (Linux)
- Build a super simple "hardware" firewall router (Linux)
- LAN Deployment Docker-- from scratch to create your own private warehouse Docker (Linux)
- Linux modify the system time (Linux)
- Transfer files to Windows and Linux (Linux)
- Tomcat session clustering and server session (Server)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.