shell if 多条件 与case语句结合出现问题
脚本如下:#!/bin/bashset-xecho"pleasechooseoneofname:"echojackechomayechomaryechoreadnamei...
脚本如下:
#!/bin/bash
set -x
echo "please choose one of name:"
echo jack
echo may
echo mary
echo
read name
if [ "$name"="jack" -o "$name"="may" -o "$name"="mary" ]
then
case "$name" in
jack | JACK )
echo "sex: man"
echo "age: 29"
echo "phone NO.:123456"
;;
mary | MARY )
echo "sex: woman"
echo "age: 33"
echo "phone NO.:654321"
;;
may | MAY )
echo "sex: woman"
echo "age: 21"
echo "phone NO.:13579"
;;
esac
else
echo "no such people"
fi
exit 0
当输入的为jack,may,mary时,输出正确,但是当输入的字符串为abc时,直接跳出,不会提示“no such people”,请问我的脚本哪里出错了呢? 展开
#!/bin/bash
set -x
echo "please choose one of name:"
echo jack
echo may
echo mary
echo
read name
if [ "$name"="jack" -o "$name"="may" -o "$name"="mary" ]
then
case "$name" in
jack | JACK )
echo "sex: man"
echo "age: 29"
echo "phone NO.:123456"
;;
mary | MARY )
echo "sex: woman"
echo "age: 33"
echo "phone NO.:654321"
;;
may | MAY )
echo "sex: woman"
echo "age: 21"
echo "phone NO.:13579"
;;
esac
else
echo "no such people"
fi
exit 0
当输入的为jack,may,mary时,输出正确,但是当输入的字符串为abc时,直接跳出,不会提示“no such people”,请问我的脚本哪里出错了呢? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询