[SWLUG] creation of temporary files/directories

Keith Edmunds keith at midnighthax.com
Mon Feb 23 07:59:29 UTC 2004


On Mon, 23 Feb 2004 03:06:16 +0000
bascule <asura at theexcession.co.uk> wrote:

> any ideas how to generate a small semi-random string in bash?

=================================================================
#!/bin/bash

RANDOM_STRING_LENGTH=8
RANDOM_STRING=""

chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_"
charlen=${#chars}	
for ((index=1; index<=RANDOM_STRING_LENGTH; ((index++)) ));
do
	a=$((RANDOM%charlen))
	RANDOM_STRING="$RANDOM_STRING${chars:a:1}"
done

echo "Random string of $RANDOM_STRING_LENGTH characters: $RANDOM_STRING"
=================================================================




More information about the Swlug mailing list