我有一个简单的脚本,我想列出一些预先填写的选项,或者让用户输入一个与编译相关的数字
这就是我目前所拥有的。
read -p "Please select from the list below or enter the build number you would like to download " build
case {build} in
Latest)
build=lastSuccessful
break;;
*)
break;;
esac
问题在于没有提供供用户选择的列表。
理想情况下,它看起来像这样
建立选择 1)最新3)成功5)选择内部版本号(1-10000) 2)稳定4)等 请从上面的列表中选择或输入您要下载的内部版本号:_
或者在2个案例陈述中做到这一点会更好吗?询问他们是否想要选择特定的版本或输入自己的版本。
更新:经过一番思考后,我最终将其简化为是否声明
while true;do
read -p "Would you like to download the latest successful build? (yes/no) " yn
case $yn in
[Yy]*)
echo
build=lastSuccessfulBuild
break;;
[Nn]*)
echo
read -p "Enter the build number to download: " build
break;;
*) echo 'I am not going to tell you again';;
[Qq]*) exit 0;;
esac
done
答案 0 :(得分:2)
select
语句可能是您想要的:
select name in Latest Successful Stable "Pick a Build Number" ;
do
case "$name" in
Latest)
build=lastSuccessful
break
;;
Successful)
build=lastSuccessful
break
;;
Stable)
build=lastSuccessful
break
;;
Pick*)
read -p "Enter a number from 1 to 10000: " number
break
;;
esac
done
这会生成菜单:
1) Latest
2) Successful
3) Stable
4) Pick a Build Number
#?
用户可以输入1,2或3,变量name
设置为相应的字符串。
答案 1 :(得分:0)
您可能也喜欢dialog
。
Chceck出来:
dialog --no-cancel --menu "Please select from the list below or enter the build number you would like to download " 11 60 12 1 Latest 2 Successful 3 Stable