Bash script to calculate time elapsed
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.
I find it very clean to use the internal variable "$SECONDS"
SECONDS=0 ; sleep 10 ; echo $SECONDS