Introduction to Linux programming-Dialog -- general Linux technology-Linux programming and kernel information. For more information, see the following section. Dialog is used in shell scripts. In fact, when you download Linux Kernel, there is a scripts/lxdialog Directory, which is actually the original dialog code, only Linux kernel changes the name to lxdialog to avoid conflicts with the original dialog. When you use "make menuconfig", you are using the dialog tool. In addition, the Slackware installer actually uses the dialog tool as the interface.
You can call dialog using shell script or perl to provide a friendly user interface.
With the dialog tool, you can use Shell Script to complete complex operation interfaces without the need to write "difficult" ncurses programs, greatly reducing product development time.
You can use "man dialog" to check its usage. Here we will make some usage and demonstration of dialog.
Dialog -- clear
The entire screen is cleared and left
Dialog -- create-rc file
Dialog supports dynamic planning, which generates a sample.
Dialog currently provides yes/no box, menu box, input box, message box, text
There are nine widgets in box, info box, checklist box, radiolist box, and gauge box.
Exit Status
If you press Yes or OK, 0 is returned. No or Cancel returns 1. If you press ESC or an error occurs,-1 is returned.
Infobox leaves immediately after the message is displayed. In the console, the message is left,
At Terminal, the X Terminal will immediately clear the message, and the Screen Shot cannot be caught. Therefore
No ScreenShot. You can test it on the console.
After the gauge widget is started, it reads percent from stdin and ends when EOF is read.
Advanced use with Shell Script
It is not enough to know how to use each function. Generally, you need to know how to use it with scripts.
Yesno, inputbox, menu, checklist, radiolist, and gauge are required.
Yesno
Example
#! /Bin/sh
DIALOG = dialog
If parameters $ DIALOG -- title "WCW v. s. NWO" -- backtitle "Wrestling "\
-- Yesno "Are you ready to rumble? "5 60; then
Echo "Yeahhhhh"
Else
Echo "Nap ..."
Fi
Inputbox
Example
#! /Bin/sh
DIALOG = dialog
If else $ DIALOG -- title "The future is here "\
-- Inputbox "Where do you want to go tomorrow? "\
10 75 "Penguin" 2> my_own_destiny
Then
Way = 'cat my_own_destiny'
Echo "My way is running $ way"
Else
Echo "freak out"
Fi
Menu
#! /Bin/sh
If dialog -- title "title "\
-- Menu "MENU" 20 60 14 \
Tag1 "item1" tag2 "item2" 2> select
Then
Selection = 'cat select'
Echo "my selection is selected $ selection"
Else
Echo "go"
Fi
Checklist
#! /Bin/sh
If dialog -- title "title "\
-- Checklist "checklist" 20 60 14 \
Tag1 "item1" on tag2 "item2" off 2> select
Then
Selections = 'cat select'
Echo "My selections are :"
For I in orders $ selections; do
Echo done $ I
Done
Else
Echo "go"
Fi
Radiolist
#! /Bin/sh
If dialog -- title "title "\
-- Radiolist "checklist" 20 60 14 \
Tag1 "item1" on tag2 "item2" off 2> select
Then
Selection = 'cat select'
Echo "My selection is selected $ selection"
Else
Echo "go"
Fi
Gauge
So far, gauge seems to have been a problem, and it is also a problem to write files. The attached sample program is also unavailable and is not recommended for use (I cannot play it myself, if you try it out, please send me a letter ).
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.