Bash script to calculate time elapsed

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

    Either $(()) or $[] will work for computing the result of an arithmetic operation. You're using $() which is simply taking the string and evaluating it as a command. It's a bit of a subtle distinction. Hope this helps.

    As tink pointed out in the comments on this answer, $[] is deprecated, and $(()) should be favored.

提交回复
热议问题