� wrote:
How about something like:
YEAR=2005 MONTH=12 for ((DAY=1;DAY<=31;++DAY)); do LC_ALL=C TZ=UTC date -d "$YEAR-$MONTH-$DAY" done | grep "^Mon " | head -n 3 | tail -n 1
Possibly without the TZ=UTC depending on your needs...
A better and faster option is to work out what day of the week the 21st falls on (e.g. Wednesday, or 4) and count back that value (minus 1 to count for Sunday):
M=12 Y=2005 echo date +%d -d $Y/$M/$((21-$(($(date +%w -d $Y/$M/21)-1))))