Created
January 30, 2018 11:06
-
-
Save dajare/368dc935ddbb212e034db73968d35b70 to your computer and use it in GitHub Desktop.
Bash shell script to return last four characters of base62 conversion of unix timestamp
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 | |
# takes unix timestamp and converts to base62 | |
# source: https://stackoverflow.com/a/14472352/232251 | |
function u2b { | |
v=$(date +%s) | |
BASE62=($(echo {0..9} {a..z} {A..Z})) | |
for i in $(bc <<< "obase=62; $v"); do echo -n ${BASE62[$(( 10#$i ))]} | |
done | |
} | |
r=$(u2b) | |
echo ${r: -4} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment