linux之whiptail交互式shell脚本对话框

简单说明

当你在linux环境下setup软件的时候就会有相应的对话框让你输入。虽然我们已经习惯了这种交互的方法,但是如果有一种直观的界面来输入是不是会更加友好和方便呢,在shell脚本中你可以使用-whiptail指令来完成。

效果如下

[root@~]# cat test.sh
#!/bin/bash
OPTION=$(whiptail --title "Test Menu Dialog" --menu "Choose your option" 15 60 4 \
"1" "Grilled Spicy Sausage" \
"2" "Grilled Halloumi Cheese" \
"3" "Charcoaled Chicken Wings" \
"4" "Fried Aubergine"  3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "Your chosen option:" $OPTION
else
    echo "You chose Cancel."
fi
[root@~]# bash test.sh

参考链接

https://github.com/eryajf/magic-of-sysuse-scripts/blob/master/a

posted @ 2024-02-29 14:38  yuhaohao  阅读(11)  评论(0编辑  收藏  举报