Last active
September 15, 2015 11:25
-
-
Save MaxChinni/8824092 to your computer and use it in GitHub Desktop.
bash number of seconds to human readable time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -ne 1 ]; then | |
echo "Usage:" >&2 | |
echo " $(basename $0) <sec>" >&2 | |
exit 1 | |
fi | |
function secToTime() { | |
local s=$1 | |
local hh=$(($s / 60 / 60)) | |
local mm=$(( ($s - $hh * 60 * 60) / 60 )) | |
local ss=$(( $s % 60 )) | |
printf "%02d:%02d:%02d" "$hh" "$mm" "$ss" | |
} | |
secToTime $1 | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment