我如何创建具有多种选择的菜单变量的shell脚本? [英] how do i create a shell script with multiple choice menu variables?
本文介绍了我如何创建具有多种选择的菜单变量的shell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面就是我要做的。
Please pick from the following
1) area1
2) area2
3) area3
Now pick a place based on the area you chose
1) place1
2) place2
3) place3
Based on $area and $place here is what you need...
我的猜测是,我需要if语句的情况下和组合,但我不能环绕这个问题我的头。
My guess is i need a combination of case and if statements but i am unable to wrap my head around the problem.
推荐答案
使用选择
语句@Barmar建议。
Use the select
statement as @Barmar suggested.
根据您的例子:
echo 'Please pick from the following'
select area in area1 area2 area3
do
case $area in
area1|area2|area3)
break
;;
*)
echo "Invalid area"
;;
esac
done
echo 'Now pick a place based on the area you chose'
select place in place1 place2 place3
do
case $place in
place1|place2|place3)
break
;;
*)
echo "Invalid place"
;;
esac
done
echo "Based on $area and $place here is what you need..."
我用 A | B | C)
将多个选择,但你可以为每一个单独的code路径。 *)
可以作为一个其他条款。使用破
打出来的菜单循环。使用 ;;
在情况下,子句之间
语句和;
一个子句中语句之间。
I used a|b|c)
to group multiple options, but you could provide separate code paths for each one. *)
can be used as an "else" clause. Use break
to break out of the menu loop. Use ;;
between clauses in the case
statement and ;
between statements in a single clause.
这篇关于我如何创建具有多种选择的菜单变量的shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文