date的使用
脚本如下:
#!/bin/bash
#file name:cost_time.sh
start=$(date +%s) #命令执行前的纪元时
$@; #以("$1""$2"...)的形式保存所有输入的命令行参数
end=$(date +%s) #命令结束时的纪元时
cost_time=$[ end - start ] #时间相减
echo "Time taken to execte commands is $cost_time seconds."
执行结果如下: