6
6

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.

シェルスクリプトで来月1日の求め方

Last updated at Posted at 2014-10-31

シェルスクリプトで来月1日を求めるのに以下のように書いていたら、本日(10/31)残念な結果になったのでメモ

# echo `date -d '1 month' +"%Y/%m/1"`
2014/12/1

(;´Д`)

正しくは以下

# echo $(date +%Y/%m/%d -d "-$(($(date +%d)-1)) days + 1 month")
2014/11/01

2014/11/10追記
上記では8日、9日に以下のようなエラーが発生した

08: value too great for base (error token is "08")

以下のように修正して対処

# echo $(date -d "`date '+%Y/%m/01'` 1 months" '+%Y/%m/01')
6
6
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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?