1. 程式人生 > >shell通過巢狀迴圈實現日期遞增輸出

shell通過巢狀迴圈實現日期遞增輸出

for i in 01 02 03 04 05 06 07 08 09 10 11 12;

do 

for j in 0 1 2 3 4 5 6;

do 

DATE=$(date +"%Y%m%d" -d "2016${i}28 +${j}day");

echo $DATE;

done;

done

輸出為

20160128
20160129
20160130
20160131
20160201
20160202
20160203
20160228
20160229
20160301
20160302
20160303
20160304
20160305
20160328
20160329
20160330
20160331
20160401
20160402
20160403
20160428
20160429
20160430
20160501
20160502
20160503
20160504
20160528
20160529
20160530
20160531
20160601
20160602
20160603
20160628
20160629
20160630
20160701
20160702
20160703
20160704
20160728
20160729
20160730
20160731
20160801
20160802
20160803
20160828
20160829
20160830
20160831
20160901
20160902
20160903
20160928
20160929
20160930
20161001
20161002
20161003
20161004
20161028
20161029
20161030
20161031
20161101
20161102
20161103
20161128
20161129
20161130
20161201
20161202
20161203
20161204
20161228
20161229
20161230
20161231
20170101
20170102
20170103