Search code examples
bashshelluuid

How to generate a uuid in shell script


Is there a way to generate uuid in shell script, similar to $RANDOM, can i use $uuidgen to get a uuid, or do i need to install any package to generate a uuid in shell script

#!/bin/bash
echo $RANDOM
echo $uuid

Solution

  • Have you tried

    uuidgen
    

    It's installed out-of-the-box on freeBSD systems like MacOS.

    On Fedora, CentOS, and RHEL, get it from the util-linux package (CentOS6 has it in util-linux-ng). On debian, get it with sudo apt-get install uuid-runtime. On other linux systems, try looking for the e2fsprogs package.