shell 实现闰年的判断

#!/bin/sh
echo "please input the year"
read year

let "n1=$year % 4"
let "n2=$year % 100"
let "n3=$year % 400"

if [ "$n1" -ne 0 ]
then
let "flag=0"
elif [ "$n2" -ne 0 ]
then
let "flag=1"
elif [ "$n3" -ne 0 ]
then
let "flag=0"
else
let "flag=1"
fi

if [ $flag -eq 1 ]
then
echo "the year input is true"
else
echo "what you input is false"
fi

posted on 2016-10-08 10:50  猫儿爹  阅读(1651)  评论(0编辑  收藏  举报

导航