为了账号安全,请及时绑定邮箱和手机立即绑定

linux shell编程中怎么判断时间相等?

linux shell编程中怎么判断时间相等?

Helenr 2019-05-27 15:06:32
linux shell编程中怎么判断时间相等
查看完整描述

4 回答

?
UYOU

TA贡献1878条经验 获得超4个赞

#!/bin/bash
echo "hello!"
T=$(date +%H)
if [ "$T" -lt "12" ];then
echo "Good moring!"
elif [ "$T" -lt "18" ];then
echo "Good afternoon!"
else
echo "Good evening!"
fi
exit 0

查看完整回答
反对 回复 2019-06-01
?
精慕HU

TA贡献1845条经验 获得超8个赞

#!/bin/sh
hour=`date +%H`
if [ $hour -lt 12 ] && [ $hour -gt 0 ]
then
echo "goodmorning"
fi
if [ $hour -lt 18 ] && [ $hour -gt 12 ]
then
echo "goodafternoon"
fi
if [ $hour -gt 18 ]
then
echo "goodevening"
fi



查看完整回答
反对 回复 2019-06-01
?
慕斯709654

TA贡献1840条经验 获得超5个赞

  • 用date命令先取得当前的时间(仅取小时数) : date '+%H'     #按24小时制取hour (00..23)

  • 然后与12进行比较,判断是不是12点之前

参考脚本代码:

12345678#!/usr/bashhh=`date '+%H'`if [ $hh -gt 12 ]then    echo "$hh behind 12"else    echo "$hh in front of 12"fi


查看完整回答
反对 回复 2019-06-01
  • 4 回答
  • 0 关注
  • 2428 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信