LoginSignup
0
0

More than 1 year has passed since last update.

Linux—シェルスクリプトで日付でループする (Mac対応あり)

Last updated at Posted at 2018-08-10
date_loop.sh
#!/bin/bash -eu

#
# YYYY-MM-DD
#
readonly start_date=2014-02-20
readonly end_date=2014-03-02

# For mac OS
#
# You need before run this script
# $ brew install coreutils
#
# shopt -s expand_aliases
# alias date=gdate

current_date="$start_date"
while true; do

        # 処理
        echo "$current_date"

        if [ "$current_date" = "$end_date" ] ; then
                break
        fi

        current_date=$(date -d "$current_date 1day" "+%Y-%m-%d")
done

結果

2014-02-20
2014-02-21
2014-02-22
2014-02-23
2014-02-24
2014-02-25
2014-02-26
2014-02-27
2014-02-28
2014-03-01
2014-03-02

バージョン

GNU bash, version 4.4.0(1)-release (x86_64-apple-darwin15.6.0)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

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
0
0