Shell script learning notes (9)-text and graphics interfaces

Source: Internet
Author: User

Text and graphics interfaces

Dialog is a tool used to create a dialog box in shell script. You can use dialog to create different information and problem windows to facilitate the script.

Dialog creates a text interface in terminal mode, and a tool compatible with the dialog syntax is called xdialog. xdialog is used to create a graphical interface in X window. Xdialog uses GTK + graphics tools to complete a variety of dialogs, which can be integrated into different desktop themes. Http://xdialog.free.fr/
In addition to xdialog, zenity can also be rewritten from gdialog.

Install: sudo apt-get install dialog xdialog zenity
Xdialog not found...

Use dialog

Currently, the following dialog box functions are supported:
Calendar, checklist, form, fselect, gauge, infobox, inputbox, inputmenu, menu, msgbox (message), password, pause, radiolist, tailbox, tailboxbg, textbox, timebox, and yesno (yes/no)

The syntax of these dialog boxes must have at least three parameters: title or information content, window height, and width.

Common usage:
Display Information: dialog -- msgbox content height and width
Press confirm to leave the status is 0, Press esc to leave the status is 255, you can use $? To check the user's response to the window.
Example

#! /Bin/bash

DIA = '/usr/bin/dialog'

$ DIA -- msgbox "Quiz 1" 10 40

X = $?

If ["$ x"-eq 0]; then
Echo "you press Enter"
Elif ["$ x"-eq 255]; then
Echo "You Press Esc"
Else
Echo "Unknown error"
Fi

Result

Progress bar

#! /Bin/bash

{
For (I = 1; I <= 10; I ++ ))
Do
Let I = 10 * I
Echo $ I
Sleep 1
Done
} | Dialog -- gauge "progress" 5 60 0

Xdialog is compatible with most dialog syntaxes. You only need to change it to Xdialog. But more diverse dialog boxes are supported ..

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.