图形化的dialog交互式脚本

类型选项含义
复选框–checklist可多选
信息框–infobox显示后即返回,但不清除屏幕
输入框–inputbox
菜单框–menu
消息框–msgbox显示后,有个ok按键,点后返回
单选框–radiolist只能选一个
文本框–textbox
是/否框–yesno

在选项列表中,使用空格键来选择。
在这里插入图片描述

#!/bin/bash
gout(){
        dialog --infobox "Thank you anyway" 5 20
        sleep 2
        dialog --clear
        exit 0
}
DISTROS=$(dialog --title "Test Checklist Dialog" --checklist \
"What is the Linux distro of your choice?" 15 60 4 \
"debian" "Venerable Debian" ON \
"ubuntu" "Popular Ubuntu" OFF \
"centos" "Stable CentOS" OFF \
"mint" "Rising Star Mint" OFF 3>&1 1>&2 2>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
         dialog --title "you choice is " --msgbox "$DISTROS"  7 25
else
        gout
fi

if [ $DISTROS == "mint" ];then
        PASSWORD=$(dialog --title "Test Password Box" \
 --passwordbox  "Enter your password and choose Ok to continue." 10 60 3>&1 1>&2 2>&3)
fi

if [ $exitstatus = 0 ]; then
         dialog --title "you passwd  is " --msgbox "$PASSWORD"  7 25
else
        gout
fi

sleep 2
dialog --clear
exit 0
man dialog
Some widgets, e.g., checklist, will write text to dialog's output.  Normally that is the standard  error,  but  there
       are options for changing this: “--output-fd”, “--stderr” and “--stdout”.  No text is written if the Cancel button (or
       ESC) is pressed; dialog exits immediately in that case.

其中3>&1 1>&2 2>&3,它交换了stdout和stderr。

https://unix.stackexchange.com/questions/42728/what-does-31-12-23-do-in-a-script

参考
https://www.programmersought.com/article/48113957799/
https://invisible-island.net/dialog/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值