To create a uuid and save it in a variable:

uuid=$(uuidgen)

On my Ubuntu system, the alpha characters are output as lower case and on my OS X system, they are output as upper case (thanks to David for pointing this out in a comment).

To switch to all upper case (after generating it as above):

uuid=${uuid^^}

To switch to all lower case:

uuid=${uuid,,}

If, for example, you have two UUIDs and you want to compare them in Bash, ignoring their case, you can do a tolower() style comparison like this:

if [[ ${uuid1,,} == ${uuid2,,} ]]

To add variety without adding external dependencies, on Linux you can do:

UUID=$(cat /proc/sys/kernel/random/uuid)

To propagate bad practices, on FreeBSD, under the linux compatibility layer (linuxulator?),

UUID=$(cat /compat/linux/proc/sys/kernel/random/uuid)
引用 https://serverfault.com/questions/103359/how-to-create-a-uuid-in-bash