思路:date -d " - 12hours" +%H判斷時間 #!/bin/bash d=`date +%H` if [ $d -ge 0 -a $d -lt 7 ];then tag=1 elif [ $d -ge 7 -a $d -lt 12 ];then tag=2 elif [ $d -ge 12 -a $d -lt 18 ];then tag=3 else tag=4 fi case $tag in 1) echo "early in the morning !" ;; 2) echo "Good morning !" ;; 3) echo "Good afternoon !" ;; 4) echo "Good evening !" ;; *) echo "Script error !" ;; esac