熱搜:win11繞過(guò)硬件限制安裝 一鍵重裝Win10系統(tǒng) 最干凈的u盤(pán)啟動(dòng)盤(pán) 真正純凈版的win7系統(tǒng)
時(shí)間:2015-07-31 14:25:52 作者:zhijie 來(lái)源:系統(tǒng)之家 1. 掃描二維碼隨時(shí)看資訊 2. 請(qǐng)使用手機(jī)瀏覽器訪問(wèn): https://m.xitongzhijia.net/xtjc/20150731/54416.html 手機(jī)查看 評(píng)論 反饋
在Linux中可以使用命令來(lái)形成對(duì)話框,Linux命令行形成的對(duì)話框就是以代碼的形式出現(xiàn)。whiptail就是一個(gè)Linux可以形成對(duì)話框的命令行,本文就來(lái)介紹一下Linux使用whiptail形成對(duì)話框的方法。
分享一個(gè)寫(xiě)好的東西。
#!/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” 是標(biāo)題,雙引號(hào)里是自己填的提示信息
--nocancel 是在這個(gè)圖文里面不顯示取消,只顯示OK
--menu “Choose your option” 15 60 4 是表示菜單提示,雙引號(hào)里是自己填的提示信息,15是高度,60是長(zhǎng)度,4是有個(gè)選擇項(xiàng)目
下面的1-4是自己的提示
最后比較關(guān)鍵,3》&1 1》&2 2》&3是為了把選擇的內(nèi)容填進(jìn)變量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?” 是可以形成一個(gè)讓用戶輸入的提示框
@shenxu.com 是默認(rèn)輸入text里的值
whiptail --msgbox “You chose Cancel.” 10 40 是顯示一行你的提示
其實(shí)還有--infobox,似乎和msgbox很像,其實(shí)不同,它基本上用不上,是在shell運(yùn)行完后,可以往前翻頁(yè)能看見(jiàn)的東西
--scrolltext 20 40是為了顯示多行的時(shí)候可以上下滾動(dòng)
另外還有--passwordbox和text一樣輸入,就是以***顯示
whiptail --checklist “choose” 15 60 2 “1” “aa” ON “2” “bb” ON
15 60還是高和寬,2是有幾個(gè)選項(xiàng),和menu一樣,后面多了一個(gè)ON或者OFF表示狀態(tài),就是菜單出來(lái)后默認(rèn)是不是選,On是選,OFF不選,用空格鍵來(lái)選擇?梢远噙x。
--radiolist,不可以多選了。ON就只能有一個(gè),其它必須是OFF
還有一個(gè)顯示進(jìn)度條的--gauge,我覺(jué)得沒(méi)啥用處。
#!/bin/bash
{
for n in `seq 100`
do
sleep 1
echo $n
done
} | whiptail --gauge “Please wait while installing” 6 60 0
以上就是Linux使用whiptail形成對(duì)話框的方法,把寫(xiě)好的代碼復(fù)制到whiptail里面就可以形成對(duì)話框了。
發(fā)表評(píng)論
共0條
評(píng)論就這些咯,讓大家也知道你的獨(dú)特見(jiàn)解
立即評(píng)論以上留言僅代表用戶個(gè)人觀點(diǎn),不代表系統(tǒng)之家立場(chǎng)