Linux裏面能夠在命令行裏造成對話框,用光標上下,左右選擇,一屏一屏的問答選擇,填寫。shell
whiptail是Linux不須要另行安裝,默認就有的,其它的好比dialog須要另行安裝,很麻煩,雖然功能比較好些。bash
帖一個寫好的東西。ide
#!/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 : 2post
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" 是標題,雙引號裏是本身填的提示信息orm
--nocancel 是在這個圖文裏面不顯示取消,只顯示OKip
--menu "Choose your option" 15 60 4 是表示菜單提示,雙引號裏是本身填的提示信息,15是高度,60是長度,4是有個選擇項目input
下面的1-4是本身的提示it
最後比較關鍵,3>&1 1>&2 2>&3是爲了把選擇的內容填進變量OPTIONio
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?" 是能夠造成一個讓用戶輸入的提示框
@shenxu.com 是默認輸入text裏的值
whiptail --msgbox "You chose Cancel." 10 40 是顯示一行你的提示
其實還有--infobox,彷佛和msgbox很像,其實不一樣,它基本上用不上,是在shell運行完後,能夠往前翻頁能看見的東西
--scrolltext 20 40是爲了顯示多行的時候能夠上下滾動
另外還有--passwordbox和text同樣輸入,就是以***顯示
whiptail --checklist "choose" 15 60 2 "1" "aa" ON "2" "bb" ON
15 60仍是高和寬,2是有幾個選項,和menu同樣,後面多了一個ON或者OFF表示狀態,就是菜單出來後默認是否是選,On是選,OFF不選,用空格鍵來選擇。能夠多選。
--radiolist,不能夠多選了。ON就只能有一個,其它必須是OFF
還有一個顯示進度條的--gauge,我以爲沒啥用處。
#!/bin/bash { for n in `seq 100` do sleep 1 echo $n done } | whiptail --gauge "Please wait while installing" 6 60 0