Reputation: 10366
I want to check if the day is Sunday, but for some reason I can't get it to work.
[[ "date '+%a'" == "Sun" ]] && echo "Today is Sunday"
Upvotes: 2
Views: 6164
Reputation: 1386
If you have multiple locales I advise to use +%u
cf. man date
:
%u day of week (1..7); 1 is Monday
Today is monday:
date +%u
1
if [[ $(date +%u) -eq 1 ]]; then
echo 'ho no :c'
fi
ho no :c
hth
Upvotes: 0
Reputation: 31
You can use the date +%u to get the day number of the week... 1 - 7 with Monday being 1 that way you should not have an issue with non-english locales
Upvotes: 3
Reputation: 798606
Use $(...)
to execute a command and return the output as a string:
[[ $(date '+%a') == "Sun" ]]
Upvotes: 6