maroph icon

Bash: create a UUID value

maroph | PRO | 08/30/16 11:32:49 AM UTC | 0 ⭐ | 356 👁️ | Never ⏰ | []
Bash |

820 B

|

None

|

0 👍

/

0 👎

# There are several ways to create a UUID in a bash script.
# UUID: https://en.wikipedia.org/wiki/Universally_unique_identifier
 
# Use the Linux kernel
uuid=`cat /proc/sys/kernel/random/uuid`
 
# Tool uuidgen
# Check if the uuidgen tool is available
# https://rpmfind.net/linux/rpm2html/search.php?query=uuidgen
# https://packages.debian.org/sid/uuid-runtime
# https://launchpad.net/ubuntu/precise/+package/uuid-runtime
uuid=`uuidgen`
 
# Java Runtime Environemnt (JRE) 6/7/8
uuid=`jrunscript -e 'java.lang.System.out.print(java.util.UUID.randomUUID().toString());'`
 
# Perl
uuid=`perl -e 'use Data::UUID;print Data::UUID->new->create_str();'`
 
# exit code 2 (ENOENT): module Data or Data::UUID not found
 
# Python 2/3
uuid=`python -c 'import uuid;print uuid.uuid1();'`
uuid=`python3 -c 'import uuid;print(uuid.uuid1());'`

Comments