티스토리 뷰

공부

[Sh] date loop

seunggabi 승가비 2020. 4. 17. 06:05
# MacOSX
START=20200101
END=20201231

if [[ "$OSTYPE" == "darwin"* ]]; then
  startDate=$(date -jf "%Y%m%d" ${START} +"%Y%m%d")
  endDate=$(date -jf "%Y%m%d" ${END} +"%Y%m%d")
else
  startDate=$(date --date=${START} +"%Y%m%d")
  endDate=$(date --date=${END} +"%Y%m%d")
fi

while true; do
  d=$startDate

  echo "$d"
  [ "$startDate" != "$endDate" ] || break

if [[ "$OSTYPE" == "darwin"* ]]; then
    startDate=$(date -jf "%Y%m%d" $(date -r $(( $(date -jf "%Y%m%d" $startDate '+%s') + 86400 )) +"%Y%m%d") +"%Y%m%d")
  else
    startDate=$(date -d "$startDate 1 day" +"%Y%m%d")
  fi
done

 

'공부' 카테고리의 다른 글

[oozie] data in coordinator  (0) 2020.04.18
[Presto] int to hex  (0) 2020.04.17
[Sh] date loop  (0) 2020.04.17
[Linux] IP  (0) 2020.04.16
[Sh] Assign output to variable  (0) 2020.04.16
[oozie] [yyyy-mm-dd't'hh:mm+0900] mask  (0) 2020.04.16
댓글
댓글쓰기 폼