diff --git a/seconds_to_time.sh b/seconds_to_time.sh new file mode 100755 index 0000000..652f3de --- /dev/null +++ b/seconds_to_time.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +function displaytime { + local T=$1 + local D=$((T/60/60/24)) + local H=$((T/60/60%24)) + local M=$((T/60%60)) + local S=$((T%60)) + [[ $D > 0 ]] && printf '%d days ' $D + [[ $H > 0 ]] && printf '%d hours ' $H + [[ $M > 0 ]] && printf '%d minutes ' $M + [[ $D > 0 || $H > 0 || $M > 0 ]] && printf 'and ' + printf '%d seconds\n' $S +} +displaytime $1