我有一个简单的脚本,我想列出一些预先填充的选项,或者让用户输入一个与构建相关的数字
这就是我目前所拥有的。
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 个 case 语句中执行此操作会更好吗?询问他们是否想要选择特定的版本或输入自己的版本。
更新:经过一番思考,我最终将其简化为是或否声明
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
A 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
被设置为相应的字符串。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)