我试图弄清楚如何解决此代码...echo -n "Enter you complaint : ";read complaint;if [[ -z $complaint ]] || [[ $complaint != 'FIRE' ]] || [[ $complaint != 'INTOXICATION' ]] || [[ $complaint != "INJURY" ]] || [[ $complaint != "BREAKAGE" ]] ;then echo "Not a good option"; exit 1;ficase $complaint in FIRE) = $complaint=$(echo "FIRE");; INTOXICATION) = $complaint=$(echo "INTOXICATION");; INJURY) = $complaint=$(echo "INJURY");; BREAKAGE) = $complaint=$(echo "BREAKAGE");;esac是否可能知道:为什么即使我键入有效的内容也总是输入?
1 回答
MM们
TA贡献1886条经验 获得超2个赞
中的条件if有误,应为:
if [[ -z $complaint ]] || [[ ( $complaint != 'FIRE' && $complaint != 'INTOXICATION' && $complaint != "BRIS" && $complaint != "BOBO" ) ]] ;then
也就是说,您想进入ifif$complaint是null(-z $complaint)或与任何有效选项都不匹配的情况,因此它必须同时与所有选项都不同,因此应&&改为||。
或者,您也可以在case...esac块中使用默认条件:
case $complaint in
FIRE) = $complaint=$(echo "FIRE");;
INTOXICATION) = $complaint=$(echo "INTOXICATION");;
INJURY) = $complaint=$(echo "INJURY");;
BREAKAGE) = $complaint=$(echo "BREAKAGE");;
*) echo "Not a good option"; exit 1;;
esac
- 1 回答
- 0 关注
- 239 浏览
添加回答
举报
0/150
提交
取消