Reputation: 10556
I'd like to create a temporary of the form /tmp/prefix.XXXXXX.suffix
, however the only function I know of to create temporary directories is mkdtemp
which requires the XXXXXX
characters to appear at the end of the template. Is there another way to create a temporary directory that allows this?
Upvotes: 0
Views: 199
Reputation: 46
This script basically creates a random six character string and uses that to make a directory.
#!/bin/bash
characters=( 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z );
charactersLength=${#characters[@]};
randomString="";
for i in `seq 6`;
do
randomNumber=$(( $RANDOM % $charactersLength ));
randomString=$randomString${characters[randomNumber]};
done
mkdir "/tmp/prefix."$randomString".suffix";
Upvotes: 0