Bash – How to compare the day of the week

bashdateshell-script

I'm trying write a script which shows right statement based on which day of the week it is. Two examples:

  1. If today is 4th day of the week. echo Today is a working day.
  2. If today is 6th day of the week. echo Today is a weekend.

I wrote this however it doesn't work

echo Hello!
echo Today's date is: date
DAY=$(date +"%u")
if [ "${DZIEN}" -ge 1 && "${DZIEN}" -le 5 ]
then 
   echo WORKING DAY;
else
   echo WEEKEND;
fi

Best Answer

Try this :

echo "Today's date is: $(date)"
day=$(date +"%u")

if ((day > 5)); then
   echo "WEEKEND"        
else
   echo "WORKING DAY"
fi

I use (( )) bash arithmetic

Or less readable :

echo "Today's date is: $(date)"
day=$(date +"%u")

if [[ day -gt 5 ]]; then
   echo "WEEKEND"        
else
   echo "WORKING DAY"
fi
Related Question