开发者社区> 问答> 正文

新手问个shell求闰年的问题? 400 报错

新手问个shell求闰年的问题? 400 报错

请大神指导,这个脚本哪里出错了?

#!/bin/sh
#  求闰年
echo "请输入要求的年份"
read year

if [ "$year"%100 = 0 ]; then
    if [ "$year"%400 = 0 ]; then
        echo "是闰年"
    else
        echo "不是闰年"
    fi                 #fi一定不能忘记

elif
    if [ "$year"%4 = 0 ]; then
        echo "是闰年"
    else
        echo "不是闰年"
    fi
fi
exit 0


展开
收起
爱吃鱼的程序员 2020-06-03 17:08:41 490 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    #!/bin/sh
    #  求闰年
    echo "请输入要求的年份"
    read year

    if [ $(expr $year % 4) == "0" ]
        then
          if [ $(expr $year % 100) != "0" ]
             then
               echo "是闰年"
          elif [ $(expr $year % 400) == "0" ]
             then
               echo "是闰年"
          else

              echo "不是闰年"

         fi

    fi
       

    2020-06-03 20:35:15
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Shell 脚本速查手册 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载