time.sh
#!/bin/bash
tm=$(date +%H)
if [ $tm -le 12 ];then
msg="Good Morning $USER"
elif [ $tm -gt 12 -a $tm -le 18 ];then
msg="Good Afternoon $USER"
else
msg="Good Night $USER"
fi
echo "The current time is:" $(date +"%Y-%m-%d %H:%M:%S")
echo -e "\033[34m$msg\033[0m"
验证:
[root@logstash ~]# sh time.sh
The current time is: 2024-05-23 14:57:18
Good Afternoon root
[root@logstash ~]#