Monday, September 17, 2018

Simple bash "UUID" generator

If you need a UUID-like string in a bash script, e.g. for the message part boundary in an email, this is probably about as simple as you can get:

#!/bin/bash

MD5SUM=/usr/local/gnu/bin/md5sum
DATE=/usr/local/gnu/bin/date

MD5=$($DATE +'%s.%N'|$MD5SUM)

B1=${MD5:0:8};B2=${MD5:8:4};B3=${MD5:12:4};B4=${MD5:16:4};B5=${MD5:20:12}

BOUNDARY="$B1-$B2-$B3-$B4-$B5"