Linux Command dialog box whiptail

Source: Internet
Author: User

Linux Command dialog box whiptail

In Linux, you can create a dialog box in the command line. Use the cursor to move the cursor up or down, select between left and right, select a question and answer screen on one screen, and fill in.
Whiptail does not need to be installed separately in Linux. It is available by default. Other types such as dialog need to be installed separately, which is very troublesome, although it has better functions.

Post a written article.
#! /Bin/bash
Trap "" 2
While true
Do
OPTION = $ (whiptail -- title "Email Manager" -- nocancel -- menu "Choose your option" 15 60 4 \
"1" "Add Email User "\
"2" "Delete Email User "\
"3" "List Email User "\
"4" "EXIT" 3> & 1 1> & 2 2> & 3)
Case $ OPTION in
1)
EmailAddress = $ (whiptail -- title "EmailAddress-form Input Box" -- inputbox "What is your add EmailAddress? "10 60 @ shenxu.com 3> & 1 1> & 2 2> & 3)
Exitstatus = $?
If [$ exitstatus = 0]; then
Grep $ EmailAddress/etc/postfix/virtual_mailbox_maps>/dev/nul
Exitstatus = $?
If [$ exitstatus = 0]; then
Whiptail -- msgbox "The Email Address is a existed" 10 40
Elif (whiptail -- title "Add Yes/No Box" -- yesno "Are you sure add $ EmailAddress." 10 60) then
/Etc/postfix/mailadd. sh $ EmailAddress
Whiptail -- msgbox "The Email Address $ EmailAddress is a added." 10 40
Fi
Else
Whiptail -- msgbox "You chose Cancel." 10 40
Fi
;;
2)
EmailAddress = $ (whiptail -- title "EmailAddress-form Input Box" -- inputbox "What is your Delete EmailAddress? "10 60 @ shenxu.com 3> & 1 1> & 2 2> & 3)
Exitstatus = $?
If [$ exitstatus = 0]; then
Grep $ EmailAddress/etc/postfix/virtual_mailbox_maps>/dev/nul
Exitstatus = $?
If [$ exitstatus! = 0]; then
Whiptail -- msgbox "The Email Address $ EmailAddress is a not exist." 10 40
Elif (whiptail -- title "Add Yes/No Box" -- yesno "Are you sure delete $ EmailAddress." 10 60) then
/Etc/postfix/maildel. sh $ EmailAddress
Whiptail -- msgbox "The Email Address $ EmailAddress is a deleted." 10 40
Fi
Else
Whiptail -- msgbox "You chose Cancel." 10 40
Fi
;;
3)
EmailAddress = $ (cat/etc/postfix/virtual_mailbox_maps | awk '{print $1 }')
Whiptail -- msgbox "The Email User list are $ EmailAddress." -- scrolltext 20 40
;;
4)
Echo "EXIT"
Break
;;
Esac
Done
Trap: 2

 


Whiptail -- title "Email Manager" -- nocancel -- menu "Choose your option" 15 60 4 \
"1" "Add Email User "\
"2" "Delete Email User "\
"3" "List Email User "\
"4" "EXIT" 3> & 1 1> & 2 2> & 3
-- Title "Email Manager" is the title, and the prompt information filled in double quotation marks is
-- Nocancel is in this image, it does not show canceled, only show OK
-- Menu "Choose your option" 15 60 4 indicates the menu prompt. The double quotation marks indicate the prompt information you entered, 15 indicates the height, 60 indicates the length, and 4 indicates a selection item.
The following 1-4 is your own prompt
The last step is critical. 3> & 1 1> & 2 2> & 3 is to fill the selected content in the variable OPTION

Whiptail -- title "EmailAddress-form Input Box" -- inputbox "What is your add EmailAddress? "10 60 @ shenxu.com 3> & 1 1> & 2 2> & 3
-- Inputbox "What is your add EmailAddress? "Is a prompt box that allows users to enter
@ Shenxu.com is the default value in text.

Whiptail -- msgbox "You chose Cancel." 10 40 is to show your prompt line
In fact, there is also -- infobox, which seems to be very similar to msgbox. In fact, it is basically not used. It is something that can be seen after shell is run.
-- Scrolltext 20 40 is used to scroll up and down when multiple rows are displayed.

In addition, the input of -- passwordbox and text is displayed ***.
Whiptail -- checklist "choose" 15 60 2 "1" "aa" ON "2" bb "ON
15 60 is still high and wide. 2 has several options. Like menu, an ON or OFF is added to indicate the status, which means whether the menu is selected by default and On is selected by default, if OFF is not selected, use the space key. You can select multiple.
-- Radiolist. You cannot select multiple. Only one ON is allowed, and the others must be OFF.
There is also a gauge that shows the progress bar, which I don't think is useful.
#! /Bin/bash
{
For n in 'seq 100'
Do
Sleep 1
Echo $ n
Done
} | Whiptail -- gauge "Please wait while installing" 6 60 0

This article permanently updates the link address:

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.