0

I am trying to get all the dates that fall between a start and end date. This is what I did

start="2022-03-02" end="2022-03-07" while [[ $start < $end ]] do echo "$start" start=$(date -d "$start + 1 day" +"%Y-%m-%d") done 

This results in an error

usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format] 

What is it I am missing?

3
  • 2
    I've tried it and it works in my environment. Output: 2022-03-02 2022-03-03 2022-03-04 2022-03-05 2022-03-06 Commented Mar 10, 2022 at 15:26
  • 3
    the code works for me; the issue is likely with your version of date; what does date --version report? Commented Mar 10, 2022 at 15:30
  • offtopic: I would rename start to something like loopdate. Most people will expect a start value to be fixed. Commented Mar 12, 2022 at 15:33

1 Answer 1

0

inspired by this answer

You can try this if you using on MacOs

date -j -v+1d -f %Y-%m-%d $start +%Y-%m-%d 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.