Nandakumar
Content Network

You are not logged in.
Click here to login.

Some part of this library is not public. You must register to get exclusive access. If you are already registered, click here to login.


Shell Programming >> 2017

Display a Time-dependent Greeting Message Using Shell Script

By | | License: proprietary


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 to the variable hour, and this is taken as the basis for decision making.

The +%H option tells the date command that it is 24-hour format hour that is to be printed (or redirected to our script)

Code
#!/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

shell sh bash linux gnu unix script programming command-line
Display a Time-dependent Greeting Message Using Shell Script | Nandakumar Content Network
Copyright © 2015, 2016, 2017 Nandakumar Edamana.