Write a shell script to prompts the user to enter the time (in 24-hour format) then wish them “Good morning”, “Good afternoon”, “Good evening”, or “Good night” based on the input. (example: If Input is 13 then print Good afternoon)
SOLUTION....
#!/bin/bash
# Script to greet user based on time input
echo "Enter the time (0-23 in 24-hour format):"
read hour
if [ $hour -ge 0 ] && [ $hour -lt 12 ]; then
echo "☀️ Good Morning!"
elif [ $hour -ge 12 ] && [ $hour -lt 17 ]; then
echo "🌤️ Good Afternoon!"
elif [ $hour -ge 17 ] && [ $hour -lt 21 ]; then
echo "🌆 Good Evening!"
elif [ $hour -ge 21 ] && [ $hour -le 23 ]; then
echo "🌙 Good Night!"
else
echo "❌ Invalid time entered! Please enter a value between 0 and 23."
fi
OUTPUT