Skip to content

Instantly share code, notes, and snippets.

@Joaquin6
Created September 11, 2018 23:53
Show Gist options
  • Save Joaquin6/e039c1c00749e77ea1c441cca40c0d74 to your computer and use it in GitHub Desktop.
Save Joaquin6/e039c1c00749e77ea1c441cca40c0d74 to your computer and use it in GitHub Desktop.
Generate s UUID in Bash
uuid()
{
local N B C='89ab'
for (( N=0; N < 16; ++N ))
do
B=$(( $RANDOM%256 ))
case $N in
6)
printf '4%x' $(( B%16 ))
;;
8)
printf '%c%x' ${C:$RANDOM%${#C}:1} $(( B%16 ))
;;
3 | 5 | 7 | 9)
printf '%02x-' $B
;;
*)
printf '%02x' $B
;;
esac
done
echo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment