shell执行不符合判断条件的if语句

#!/bin/bashreadyearlet"y1=$year%4"let"y2=$year%400"let"y3=$year%100"if["$y2"==0];then... #!/bin/bash
read year
let "y1= $year % 4"
let "y2= $year %400"
let "y3= $year %100"
if [ "$y2" == 0 ]; then
m2=29
elif [ "$y2" == 0 ] && [ "$y3" != 0 ]; then
m2=29
else
m2=28
fi
if [ "$m2" == 28 ]; then
days=365
else
days=366
fi
echo "$days"
read bm
read bd
if [ "$bm" == 1 ]; then
let "a= $bd"
elif [ "$bm" == 2 ]; then
let "a= 31+bd"
elif [ "$bm" == 3 ]; then
let "a= 31+m2+bd"
elif [ "$bm" == 4 ]; then
let "a= 62+m2+bd"
elif [ "$bm" == 5 ]; then
let "a= 92+m2+bd"
lif [ "$bm" == 6 ]; then
let "a= 123+m2+bd"
elif [ "$bm" == 7 ]; then
let "a= 153+m2+bd"
elif [ "$bm" == 8 ]; then
let "a= 184+m2+bd"
elif [ "$bm" == 9 ]; then
let "a= 215+m2+bd"
elif [ "$bm" == 10 ]; then
let "a= 245+m2+bd"
elif [ "$bm" == 11 ]; then
let "a= 276+m2+bd"
else
let "a= 306+m2+bd"
fi
read nm
read nd
if [ "$nm" == 1 ]; then
let "b= $nd"
elif [ "$nm" == 2 ]; then
let "b= 31+nd"
elif [ "$nm" == 3 ]; then
let "b= 31+m2+nd"
elif [ "$nm" == 4 ]; then
let "b= 62+m2+nd"
elif [ "$nm" == 5 ]; then
let "b= 92+m2+nd"
elif [ "$nm" == 6 ]; then
let "b= 123+m2+nd"
elif [ "$nm" == 7 ]; then
let "b= 153+m2+nd"
elif [ "$nm" == 8 ]; then
let "b= 184+m2+nd"
elif [ "$nm" == 9 ]; then
let "b= 215+m2+nd"
elif [ "$nm" == 10 ]; then
let "b= 245+m2+nd"
elif [ "$nm" == 11 ]; then
let "b= 276+m2+nd"
else
let "b= 306+m2+nd"
fi
echo "$a"
echo "$b"

if [ "$a" > "$b" ]; then
let "c= $a-$b"
fi
if [ "$a" < "$b" ]; then
let " c= $days-$b+$a"
fi
echo "$c"
当a>b时,为什么在执行第一个if语句后,会接着执行第二个if语句,明明不符合判断条件
展开
 我来答
良玉小帝
2018-03-07 · 个人日常精心汇总合集
良玉小帝
采纳数:5925 获赞数:9451

向TA提问 私信TA
展开全部
又不是else
当然执行了第一个if
会执行第二个if
正常逻辑啊
更多追问追答
追问
shell执行了第一个if,此时已经是a>b的条件了了,不符合第二个a<b的判断条件,但是shell还是会执行第二个if并改变c的值
追答
你是数字吗。不应该这样啊
“”就转换成字符串了
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式