From 6e84f4762416e8658ef08ca3455be36a007ce80e Mon Sep 17 00:00:00 2001 From: daryl Date: Fri, 1 Jul 2022 10:18:56 +0930 Subject: [PATCH] Add 'bash/script_runtime.bash' --- bash/script_runtime.bash | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 bash/script_runtime.bash diff --git a/bash/script_runtime.bash b/bash/script_runtime.bash new file mode 100644 index 0000000..b05f74c --- /dev/null +++ b/bash/script_runtime.bash @@ -0,0 +1,11 @@ +#!/bin/bash + +sleep 5000 + +secs=$SECONDS # utilise bash builtin SECONDS +hrs=$(( secs/3600 )); mins=$(( (secs-hrs*3600)/60 )); secs=$(( secs-hrs*3600-mins*60 )) # integer maths gives whole numbers + +printf 'Time spent: %02d:%02d:%02d\n' $hrs $mins $secs + +# output would be +# Time spent: 01:23:20