> > I am not 100% sure how to do the job with NetBSD's date(1). I may > > be just lucky with > > % date -d '+1 month 1 thu' > > Thu Aug 6 00:00:00 CEST 2020 > > because today is the 1st of July. > > Why wait? Try [...]
Because yesterday was unsuitable to check for the ambiguity how the second "1" in that expression is actually parsed. Is it parsed as in: (+1 month 1) thu as in "go next month, its 1st, forward to Thursday", or is it: +1 month (1 thu) as in "go next month (same day as today, i.e. 2nd NOW), forward 1 thu". This would skip the weekdays already passed, such as the upcoming Saturday on Aug 1st. And indeed: $ date -d '+1 month 1 sat' Sat Aug 8 00:00:00 CEST 2020 That is: the expression is, alas, *not* good enough to compute the "first $WEEKDAY of next month". I am at a loss how to do this with NetBSD's date(1). This wasn't decidable yesterday, and I wrote: > > I better recheck this in a fortnight. because the "Thursday" check, one-shot or ranged as in > for i in 1 2 3 4 5 6 7 8 9 10 > do > date -d "+$i month 1 thu" > done will not fail immediately but more and more blatantly as we progress into the month. Martin Neitzel PS: The () in the date expressions above are just to illustrate possible parsings. The actual date command treats "(stuff)" as a comment.