Bash script to calculate time elapsed

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

    You are trying to execute the number in the ENDTIME as a command. You should also see an error like 1370306857: command not found. Instead use the arithmetic expansion:

    echo "It takes $(($ENDTIME - $STARTTIME)) seconds to complete this task..."
    

    You could also save the commands in a separate script, commands.sh, and use time command:

    time commands.sh
    

提交回复
热议问题