0

As part of a Bash script how can I get the Day of the week + x days. This should be the Day of the Week (e.g. Monday, Tuesday, . . .)

e.g.

startDate='Sunday'
addDays=6
endDate=${startDate}+${addDays} #e.g. Saturday

or  

startDate='Tuesday'
endDate=${startDate}+${addDays} #e.g. Monday
1

Use GNU date!

startDate='Sunday'
addDays=6
endDate=$( date -d "${startDate} + ${addDays} days" '+%A' )

$ echo $endDate
Saturday
| improve this answer | |
1
date -d "6 days" +%A

Date uses the current date, so it can easily show the name what will 6 days later ( %A locale's full weekday name (e.g., Sunday))

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.