打印错误后我需要从 2 或 3 恢复到 1 吗?
1 echo -e "program set defulte home dirctory /home/admin/$un"
echo -e "DO you want use defulte home dirctory? Yes=1 & NO=2"
read -a hd1
case $hd1 in
1)
hd=`/home/admin/$un` #40
echo -e "your home dirctory $hd1 " ;;
2)
echo -e "Please insert name your home dirctory between 1 to 10 character:"
read -a hda
len1=${#hda}
if [ "$len1" -eq "$ze" ];then
echo "There is no Argument home dirctory" # error message
2 exit
fi
if [ "$len1" -ge "$te" ];then #50
echo "The argument home dirctory maximum 10 alphanumeric" # error message
3 exit
fi
hd=`/home/admin/$hda`;;
*) echo " You have selected wrong Choice!!!" ;;
esac
答案1
使用 while 循环保持问题运行,完成后退出,如下所示
while :; do # : evaluates to true, so "while true; do ...; done"
echo "Choose A or B"
read answer
case "$answer" in
[Aa]) # match case-insensitive A
echo "A was chosen"
break # leave the while-loop
;;
[Bb]) # match case-insensitive B
echo "B was chosen"
break # leave the while-loop
;;
*)
echo "Please choose A or B only"
;;
esac
done