#!/bin/bash

判断平年和闰年

read -p '请输入年份:' year

if [ $((year%4)) -eq 0 ] && [ $((year%100)) -ne 0 ] || [ $((year%400)) -eq 0 ] then echo '$year 是闰年' else echo '$year 是平年' fi

说明:

1、判断闰年的条件是:能被4整除但不能被100整除,或者能被400整除;

2、使用$((...))来进行数值计算;

3、使用[]来进行条件判断。

Xshell7 脚本判断平年和闰年 - 简单易懂教程

原文地址: https://www.cveoy.top/t/topic/nlJj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录