Linux uses whiptail to form dialog box method

  

In Linux, commands can be used to form dialog boxes. The dialog box formed by Linux command line is in the form of code. Whiptail is a command line that Linux can form a dialog box. This article will introduce Linux's method of using whiptail to form a dialog box.

share something of a written.

#! /bin/bash

trap “” 2

while true

do

OPTION=$(whiptail --title “Email Manager” --nocancel --menu “Choose your option& rdquo; 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 <; Email Address $EmailAddress is a added.” 10 40

fi

else

whiptail --msgbox “You chose Cancel.” 10 40< Br>

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&rdquo ; --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, double quotes are filled out by yourself

--nocancel is in This graphic does not display the cancellation, only the OK

--menu “Choose your option" 15 60 4 is the menu prompt, the double quotes are filled in the prompt information, 15 is high , 60 is the length, 4 is a selection item

The following 1-4 are their own tips

The last comparison is key, 3"&1 1"&2 2"& 3 is to fill the selected content into 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? ” can form a prompt box for user input

@shenxu.com is the default input text value

whiptail --msgbox “You chose Cancel.” 10 40 yes Show a line of your tips

In fact, there is --infobox, it seems to be very similar to msgbox, in fact, it is basically not used, it is something that can be seen when the shell is running.

--scrolltext 20 40 is to scroll up and down when displaying multiple lines

In addition, --passwordbox is input like text, which is displayed as ***

Whiptail --checklist “choose” 15 60 2 “1” “aa” ON “2” “bb” ON

15 60 is still high and wide, 2 is there are several options, and Like the menu, there is an ON or OFF status after the menu, that is, the default is not selected after the menu comes out, On is selected, OFF is not selected, use the space bar to select. Can choose more.

--radiolist, you can't choose more. There can only be one ON, others must be OFF

There is also a --gauge showing the progress bar, which I feel is useless.

#! /bin/bash

{

for n in `seq 100`

do

sleep 1

echo $n

done

} |  Whiptail --gauge “Please wait while installing" 6 60 0

The above is the way Linux uses whiptail to form a dialog box. Copy the written code into the whiptail to form a dialog box.

Copyright © Windows knowledge All Rights Reserved