用shell问候程序,它执行时能根据实时的系统时间输出问候语句。设从半夜到中午为早晨,中午到下午六点为下午,下午六点到半夜为晚上。
如图:
其中:-ge是大于等于,-le是小于等于,通过二者将时间与hour进行比较来选择输出问候语句。
#!/bin/sh -
hour=`data +%H`
if test "$hour" -ge 0 -a "$hour" -le 11;then
echo "Good morning"
elif test "$hour" -ge 12 -a "$hour" -le 17;then
echo "Good afternoon"
else
echo "Good evening"
fi