#!/bin/bash

function ShowTime()
{
    endTime=`date +'%Y-%m-%d %H:%M:%S'`
    start_seconds=$(date --date="$startTime" +%s);
    end_seconds=$(date --date="$endTime" +%s);
    usedTime=$((end_seconds-start_seconds))
    # 超过2秒用红色字体显示,1-2s用黄色字体显示,1s以内用绿色字体显示
    if [[ $usedTime -ge 2 ]]
    then
        echo -e "\033[31mUsed time:$usedTime s \033[0m"
    elif [[ $usedTime -ge 1 ]]
    then
        echo -e "\033[33mUsed time:$usedTime s  \033[0m"
    else
        echo -e "\033[32mUsed time:$usedTime s \033[0m"
    fi
}


startTime=`date +'%Y-%m-%d %H:%M:%S'`
echo "Start time:$startTime"
# 执行程序
sleep 1
ShowTime

cxduan
1 声望0 粉丝

引用和评论

0 条评论