1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

シェルスクリプトでうるう年

Last updated at Posted at 2019-01-21

#うるう年のスクリプト
会社でLPICの研修を受ける中、雑談の中で出た入力した年がうるう年か否かを判定する
簡単なスクリプトを、シェルスクリプトのifを使って書きました、その備忘録になります。

uruu.sh
#!/bin/bash

echo "確認したい年を入力してください"
read year

year4=`expr $year % 4`
echo $year4

if [ `expr $year % 4` -eq 0 ]
then
    if [ `expr $year % 100` -eq 0 ]
    then
        if [ `expr $year % 400` -eq 0 ]
        then
            leapyear=true
        else
            leapyear=false
        fi
    else
        leapyear=true
    fi
else
    leapyear=false
fi

if [ $leapyear = true ]
then
    echo "うるう年です"
else
    echo "うるう年ではありません"
fi

以上になります。もっと簡素なやり方もあるかとは思いますが、現状こんな感じです。

1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?