bash 脚本:如何使用对话框获取无线电列表上的项目名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8794888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:15:50  来源:igfitidea点击:

bash scripting: how to get item name on a radiolist using dialog

linuxbashshelldialog

提问by Ivan

i need to make a radiolist in bash script using dialog interface, for example if i have the following list:

我需要使用对话框界面在 bash 脚本中制作一个radiolist,例如,如果我有以下列表:

dialog --backtitle "OS infomration" \
--radiolist "Select OS:" 10 40 3 \
 1 "Linux 7.2" off \
 2 "Solaris 9" on \
 3 "HPUX 11i" off

I want that when the user choose an option and press ok my scripts read the item name (and not the item number).

我希望当用户选择一个选项并按确定时,我的脚本读取项目名称(而不是项目编号)。

It is possible? Thanks!

有可能的?谢谢!

采纳答案by jordanm

You can put your expected results in an array:

您可以将您的预期结果放在一个数组中:

array=(Linux Solaris HPUX)
var=$(dialog --backtitle "OS infomration" \
--radiolist "Select OS:" 10 40 3 \
 1 "Linux 7.2" off \
 2 "Solaris 9" on \
 3 "HPUX 11i" off >/dev/tty 2>&1 )

printf '\n\nYou chose: %s\n' "${array[var - 1]}"