lock() { if ! mkdir "$1" &>/dev/null; then while true; do sleep 2; if [[ ! -d "$1" ]]; then return fi done fi; } if [[ "$#" -eq "1" ]]; then lock $1 else echo "please supply one argument: the lock folder" exit 1 fi