Based on the algorithm in Wikipedia, this script takes a four-digit year as an argument, and determines whether or not it is a leap year. Obviously not super-useful in itself, the "if" line could be incorporated into a larger script. Appears to work in ksh and bash, but not sh.
year=$1
if [ $((year%400)) -eq 0 ] || \
( [ $((year%4)) -eq 0 ] && [ $((year%100)) -ne 0 ] )
then
echo "leap"
else
echo "not leap"
fi
End of the road
1 year ago
0 comments:
Post a Comment