In linux how to get the date of the first day of the week monday.
I know that date +"%u" gives the current day of the week from this how to get the date of the monday of that week
In linux how to get the date of the first day of the week monday.
I know that date +"%u" gives the current day of the week from this how to get the date of the monday of that week
The date
command is very flexible about the input it will take from -d
Try this
#!/bin/bash
if [ $(date +%u) -eq "1" ]
then
date
else
date -d "last monday"
fi
You can do
date --date="Monday"
to get the date of this Monday. You can also do
date --date="next Monday"
to get the date of the next Monday. You can also use "last Monday" to get the date of the previous Monday.
Refer to the Man pages for more details.