The following shell script displays "Good morning!", "Good afternoon!" or "Good evening!" based on the time it gets executed. It stores the output of
date +%H in the variable hour, and this is taken as the basis for decision making.
+%H option tells the date command that it is 24-hour format hour that is to be printed (or redirected to our script).
#!/bin/sh hour="$(date +%H)" # Hour of the day if [ "$hour" -lt 12 ]; then echo "Good morning!" elif [ "$hour" -lt 16 ]; then echo "Good afternoon!" else echo "Good evening!" fi