Created
July 11, 2012 21:31
-
-
Save hfs/3093718 to your computer and use it in GitHub Desktop.
Print a time interval given in seconds in human readable form: 2d 13h 7m 0s
This file contains hidden or 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
human_time() { | |
seconds=$1 | |
d=$(( $seconds / 86400 )) | |
h=$(( $seconds / 3600 % 24 )) | |
m=$(( $seconds / 60 % 60 )) | |
seconds=$(( $seconds % 60 )) | |
for unit in d h m; do | |
eval value=\$$unit | |
if [ $value -gt 0 ]; then | |
printing=true | |
fi | |
if [ "$printing" ]; then | |
echo -n "$value$unit " | |
fi | |
done | |
echo "${seconds}s" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment