Bash script to calculate time elapsed

后端 未结 10 1486
被撕碎了的回忆
被撕碎了的回忆 2021-01-29 22:03

I am writing a script in bash to calculate the time elapsed for the execution of my commands, consider:

STARTTIME=$(date +%s)
#command block that takes time to c         


        
10条回答
  •  佛祖请我去吃肉
    2021-01-29 22:13

    start=$(date +%Y%m%d%H%M%S);
    for x in {1..5};
    do echo $x;
    sleep 1; done;
    end=$(date +%Y%m%d%H%M%S);
    elapsed=$(($end-$start));
    ftime=$(for((i=1;i<=$((${#end}-${#elapsed}));i++));
            do echo -n "-";
            done;
            echo ${elapsed});
    echo -e "Start  : ${start}\nStop   : ${end}\nElapsed: ${ftime}"
    
    Start  : 20171108005304
    Stop   : 20171108005310
    Elapsed: -------------6
    

提交回复
热议问题