工作环境:Red Hat Enterprise Linux Server release 6.5 (Santiago) 、 bash
#!/bin/bash
#
hour=`date +%H`
min=`date +%M`
end_hour=$(echo "17-$hour"|bc)
end_min=$(echo "30-$min"|bc )
if [ $end_hour -lt 0 ];then
echo "现在已是放学时间"
exit
fi
if [ $end_min -lt 0 ];then
end_min=$(echo "$end_min+60"|bc)
((end_hour--))
fi
echo "离放学还差$end_hour小时$end_min分钟"