Linux下shell编程出现too many arguments的问题
shell代码:echo"输入Y或N";readANSWER;if[$ANSWER="Y"or$ANSWER="y"]thenecho$ANSWER;elseecho$A...
shell代码:
echo "输入Y或N";
read ANSWER;
if [ $ANSWER ="Y" or $ANSWER ="y" ]
then
echo $ANSWER;
else
echo $ANSWER;
fi
为什么我执行这个shell,输入Y或者y时,显示line 3: [: too many arguments
哪里错了? 展开
echo "输入Y或N";
read ANSWER;
if [ $ANSWER ="Y" or $ANSWER ="y" ]
then
echo $ANSWER;
else
echo $ANSWER;
fi
为什么我执行这个shell,输入Y或者y时,显示line 3: [: too many arguments
哪里错了? 展开
3个回答
展开全部
没有or的写法,下面可供参考
echo "输入Y或N";
read ANSWER;
if [ "$ANSWER" = "Y" ] || [ "$ANSWER" == "y" ]
then echo $ANSWER;
else echo $ANSWER;
fi
echo "输入Y或N";
read ANSWER;
if [ "$ANSWER" = "Y" ] || [ "$ANSWER" == "y" ]
then echo $ANSWER;
else echo $ANSWER;
fi
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if [ $ANSWER ="Y" or $ANSWER ="y" ]
#改为
if [[ $answer == "y" ]]||[[ $answer == "Y" ]]
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询