我为这个问题太简单而道歉,但我目前正在学习。
我在Linux中使用dialog,我想要一个带我到另一个对话框菜单的选项,有更多的选项,基本上是另一个菜单。
HEIGHT=15
WIDTH=40
CHOICE_HEIGHT=4
BACKTITLE="this is a back title"
TITLE="title"
MENU="Choose one of the following options:"
MENU2="This is another menu"
OPTIONS=(1 "Install this"
2 "menu 2"
3 "menu 3"
4 "menu 4")
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
clear
case $CHOICE in
1)
mkdir -p /opt/test
;;
2)
Dialogue_menu_2
;;
3)
echo "test3"
;;
4)
echo "worked"
;;
esac ```
This is what I have so far I just can't see how I can get it working. Apologies again but I cannot find much online about this tool.
发布于 2021-09-02 08:10:33
我使用函数来做这件事
像这样的东西
#!/bin/bash
function menu1(){
local HEIGHT=15
local WIDTH=40
local CHOICE_HEIGHT=4
local BACKTITLE="this is a back title"
local TITLE="Menu 1"
local MENU="Choose one of the following options:"
local OPTIONS=(
1 "Install this"
2 "menu 2"
3 "test 3"
4 "test 4"
)
local CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty
)
echo $CHOICE
}
function menu2(){
local HEIGHT=15
local WIDTH=40
local CHOICE_HEIGHT=4
local BACKTITLE="this is a back title"
local TITLE="Menu 2"
local MENU="Choose one of the following options:"
local OPTIONS=(
1 "Option 1"
2 "Option 2"
3 "Option 3"
4 "Option 4"
)
local CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty
)
echo $CHOICE
}
# Main
# Call menu1 and register in $RET1
RET1=$(menu1)
case $RET1 in
1)
mkdir -p /opt/test
;;
2)
#Call menu2 and register in $RET2
RET2=$(menu2)
echo "You choose for menu 1: $RET1"
echo "You choose for menu 2: $RET2"
;;
3)
echo "test3"
;;
4)
echo "worked"
;;
esac
调用函数menu1,并将所选选项存储在$RET1中并由案例使用
menu1
└─> echo "Install this"
└─> Call function menu2
└─> echo "choose menu1: "
└─> echo "choose menu2: "
└─> echo "test3"
└─> echo "test4"
我希望这是最清楚的:-)
https://stackoverflow.com/questions/67551624
复制相似问题