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
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.