Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
2 of 2 added 623 characters in body

In ksh93:

$ printf '%(%F)T\n' 'next month, first Monday'

bash, since 4.2 now supports a %(<format)T in its printf buitin, but not the ability to parse this kind of date expression.

If you had to use bash and wanted to use that %(<format>)T, you could still do it without forking with something like:

printf -v code '%(
  t=$((%s + (12 - %-H) * 60 * 60))
  increment=$((8 - %u))
  current_month=%m)T' -1
eval "$code"
  t=$((t + increment * 24 * 60 * 60)) # next Monday around mid-day
  printf -v code '%(date=%F month=%m)T' "$t"
  eval "$code"
  [ "$month" != "$current_month" ] # until be get to next month
  increment=7 # the first increment is the number of days
              # til Monday. Next increments are just a week.
echo "$date"