Doesn't matter how long you've been using a GNU/Linux shell, you'll always learn something new every day.
Thanks for this.
$ echo $SECONDS
83783
$ echo $SECONDS
83784
$ echo $SECONDS
83787 $ echo "$SECONDS / 60 / 60" | bc
362.38500000000000000000# will give 2 digits after the decimal point, instead of bc -l which gives more digits of precision after the decimal point, than we may usually want for this particular calculation.
awk "BEGIN { print int($SECONDS /60 /60)}"Modifying my example from above:
echo "scale=0; $SECONDS / 60 / 60" | bc
might also work, need to check.
$ time sleep 2
real 0m2.003s
user 0m0.002s
sys 0m0.001s
# At top of script
SECONDS = 0
# script commands
...
# At bottom of script
duration=$SECONDS
echo "$(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
Use $((RANDOM + (RANDOM << 15))) instead.
> Doesn't matter how long you've been using a GNU/Linux shell
Or a Unix shell, even.