Linux使用whiptail形成对话框的方法


在Linux中可以使用命令来形成对话框,Linux命令行形成的对话框就是以代码的形式出现。whiptail就是一个Linux可以形成对话框的命令行,本文就来介绍一下Linux使用whiptail形成对话框的方法。

分享一个写好的东西。

#!/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 是标题,双引号里是自己填的提示信息

--nocancel 是在这个图文里面不显示取消,只显示OK

--menu Choose your option 15 60 4 是表示菜单提示,双引号里是自己填的提示信息,15是高度,60是长度,4是有个选择项目

下面的1-4是自己的提示

最后比较关键,3》&1 1》&2 2》&3是为了把选择的内容填进变量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? 是可以形成一个让用户输入的提示框

@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


上一篇:Linux信号机制解析

下一篇:Linux系统reconfig命令的使用说明


Linux命令行 linuxwhiptail Linux对话框
Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器