亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 2606 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號