类型 | 选项 | 含义 |
---|---|---|
复选框 | –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/