计算shell 脚本的执行时间

# shell_time.sh

#!/bin/bash

UseTime () {
    startTime_s=`date +%s` # 获取从1970-01-01 00:00:00 UTC到现在的秒数
    $Command
    endTime_s=`date +%s`
    sumTime=$[ $endTime_s - $startTime_s ]
    echo "$startTime ---> $endTime" "Totl:$sumTime second"  >> /tmp/usertime.txt
}


hello () {
    echo "hello !"
    sleep 8
}


Command=hello
UseTime $Command
# cat /tmp/usertime.txt
20210303-16:30 ---> 20210303-16:32 Totl:2 minutes
 --->  Totl: second
 --->  Totl:8 second
原文地址:https://www.cnblogs.com/sanduzxcvbnm/p/14475375.html