A shell script is a computer program designed to be run by the Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text. A script that sets up the environment, runs the program, and does any necessary cleanup, logging, etc. is called a wrapper.
In this post, we will write a shell script to print good morning, good afternoon, good evening and good night according to the system time.
Print one line: the greeting according to the system time
The following is the shell script to print good morning, good afternoon, good evening and good night according to the system time:
h=$(date +"%H") if [ $h -gt 6 -a $h -le 12 ] then echo good morning elif [ $h -gt 12 -a $h -le 16 ] then echo good afternoon elif [ $h -gt 16 -a $h -le 20 ] then echo good evening else echo good night fi
$ good evening
Let us know in the comments if you are having any questions regarding this shell script.
And if you found this post helpful, then please help us by sharing this post with your friends. Thank You