shell case in 返回问题
下面脚本里第三选择想实现返回 echo "选择yes/no" ,用了while true;do ,retrun 0 虽然能实现功能,但是一直报错 return: can only `return' from a function or sourced script, help!!!
#!/bin/bash
echo "选择yes/no"
read chooise
case $chooise in
yes)
echo "1111"
;;
no)
exit 0
;;
*)
echo "重新选择"
;;
esac
「最上川」
9 years, 11 months ago
Answers
我不是特别清楚,我写了一个或许可以使用,还有完善的地方。
#!/bin/bash
echo "选择yes/no"
flag=1
ret=0
#read chooise
while [ $flag -eq 1 ]; do
read chooise
case $chooise in
yes)
echo "1111"
let ret=1
let flag=0
;;
no)
#exit 0
let ret=0
let flag=0
;;
*)
echo "重新选择"
;;
esac
done
echo $flag
echo $ret
chaozzx
answered 9 years, 11 months ago