Skip to content

Instantly share code, notes, and snippets.

@aljex aljex/mk_tmp_dir.sh
Created Mar 27, 2019

Embed
What would you like to do?
Example to create an exclusive temp/working dir in bash using the atomicity of mkdir without -p
#!/bin/bash
# example
# create an exclusive temp dir
# atomic mkdir op method
# allow bash-isms
# bw.aljex@gmail.com
b="${1:-/tmp/foo}"
mkdir -p "${b%/*}" || exit 1
n=0 x="${b}_00000000"
until mkdir "${x}" ;do printf -v x "%s_%08d" "${b}" $((++n)) ;done
echo "${x}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.