Reputation: 1011
I'm trying to get the date to work properly. The time is 5 pm (1700 hours) now i.e. evening but it always says morning. Here's my code
currenthour="$(date "+ %-H")"
echo $currenthour
if [ $currenthour -gt '12' ] && [ $currenthour -lt '16' ]; then
currenttimeofday="Afternoon"
elif [ $currenthour -gt '16' ] && [ $currenthour -lt '1' ]; then
currenttimeofday="Evening"
else
currenttimeofday="Morning"
fi
echo $currenttimeofday
Upvotes: 0
Views: 60
Reputation: 5599
You need to remove the space between the plus and the percentage symbol, your variable then will be used properly in the condition.
Upvotes: 1