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语句,明明不符合判断条件 展开
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语句,明明不符合判断条件 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询