Bash script to calculate time elapsed

后端 未结 10 1487
被撕碎了的回忆
被撕碎了的回忆 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:35

    try using time with the elapsed seconds option:

    /usr/bin/time -f%e sleep 1 under bash.

    or \time -f%e sleep 1 in interactive bash.

    see the time man page:

    Users of the bash shell need to use an explicit path in order to run the external time command and not the shell builtin variant. On system where time is installed in /usr/bin, the first example would become /usr/bin/time wc /etc/hosts

    and

    FORMATTING THE OUTPUT
    ...
        %      A literal '%'.
        e      Elapsed  real  (wall  clock) time used by the process, in
                     seconds.
    

提交回复
热议问题