You ought to be able to use a nested if. Something like this:
Code:
#!/bin/bash
# Check if weekday or not
if [[ $(date +u) < 6 ]]; then
if [[ $(date +%H) > 15 ]]; then
echo "A weekday after 3pm (15:00 hours)."
echo "Play from evening directory"
else
echo "A weekday before 3pm (15:00 hours)"
fi
else
echo "Play from weekend directory"
fi
Upon execution (now, at fri 14 aug 2015 19:06:25 CEST), I get this result:
Code:
$ ./check_day_time.sh
A weekday after 3pm (15:00 hours).
Play from evening directory
If I simulate -7 hours:
Code:
#!/bin/bash
# Check if weekday or not
if [[ $(date +%u) < 6 ]]; then
#if [[ $(date +%H) > 15 ]]; then
if [[ $(date -d '7 hour ago' "+%H") > 15 ]]; then
echo "A weekday after 3pm (15:00 hours)."
echo "Play from evening directory"
else
echo "A weekday before 3pm (15:00 hours)"
fi
else
echo "Play from weekend directory"
fi
I get this result.
Code:
./check_day_time.sh
A weekday before 3pm (15:00 hours)
And finally, if I simulate a weekend:
Code:
!/bin/bash
# Check if weekday or not
#if [[ $(date +%u) < 6 ]]; then
if [[ $(date -d '+1 day' "+%u") < 6 ]]; then
#if [[ $(date +%H) > 15 ]]; then
if [[ $(date -d '7 hour ago' "+%H") > 15 ]]; then
echo "A weekday after 3pm (15:00 hours)."
echo "Play from evening directory"
else
echo "A weekday before 3pm (15:00 hours)"
fi
else
echo "Play from weekend directory"
fi
I get this result:
Code:
$ ./check_day_time.sh
Play from weekend directory
Best regards,
HMW