views:

60

answers:

4

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"
+4  A: 

Use $(...) to execute a command and return the output as a string:

[[ $(date '+%a') == "Sun" ]]
Ignacio Vazquez-Abrams
Better make that command "LC_ALL=C date +'%a'" or that shell script will cease to work as soon as someone runs it with a non-English locale set.
ndim
ahhh ... perfect thx
luckytaxi
Or better yet, use `%w` so that it gives you a number.
Ignacio Vazquez-Abrams
A: 
[[ $(date '+%a') == "Sun" ]] && echo "Sunday!"
LucaB
A: 

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

Courtland Halbrook
A: 
case "$(date '+%a')" in "Sun" ) echo "sunday";; esac
ghostdog74