Skip to content

Instantly share code, notes, and snippets.

@pythonhacker
Last active February 15, 2022 15:22
Show Gist options
  • Save pythonhacker/95117153f84c98cff57f9bfdb7e11456 to your computer and use it in GitHub Desktop.
Save pythonhacker/95117153f84c98cff57f9bfdb7e11456 to your computer and use it in GitHub Desktop.
A pure bash function for creating UUIDs with no dependencies
function uuidgen() {
chunks=(4 2 2 2 6)
elems=()
for c in ${chunks[@]}; do
hex_chunk=$(xxd -l $c -p /dev/urandom)
elems+=( $hex_chunk )
done
uuid=$(IFS=-, ;echo "${elems[*]}")
echo $uuid
}
uuidgen
@pythonhacker
Copy link
Author

$ uuid_gen.sh 
2ae7f033-ef8b-4f2a-67f1-5ab397e2a942
(infra) anand@antiXthink1:~/work/repos/drishti-data-platform
$ uuid_gen.sh 
f4704c93-6daf-337d-b1cb-919464ee908d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment