| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced |
| 4 |
# at the Lawrence Livermore National Laboratory. All Rights reserved. See files |
| 5 |
# LICENSE and NOTICE for details. LLNL-CODE-806117. |
| 6 |
# |
| 7 |
# This file is part of the MFEM library. For more information and source code |
| 8 |
# availability visit https://mfem.org. |
| 9 |
# |
| 10 |
# MFEM is free software; you can redistribute it and/or modify it under the |
| 11 |
# terms of the BSD-3 license. We welcome feedback and contributions, see file |
| 12 |
# CONTRIBUTING.md for details. |
| 13 |
|
| 14 |
# This script takes a seed for a directory name and appends it with a counter |
| 15 |
# incremented until it can create a new directory with it. |
| 16 |
|
| 17 |
# Usage: |
| 18 |
# |
| 19 |
# Expects 1 argument: a string that is use as a seed for the directory name. |
| 20 |
# |
| 21 |
# > rundir="desired_name" |
| 22 |
# > rundir=$(./safe_create_rundir $rundir) |
| 23 |
|
| 24 |
set -o errexit |
| 25 |
set -o nounset |
| 26 |
|
| 27 |
rundir=${1:-""} |
| 28 |
if [[ -z ${rundir} ]]; then |
| 29 |
>&2 echo "The script expects a string as argument for directory creation." |
| 30 |
exit 1 |
| 31 |
fi |
| 32 |
|
| 33 |
if ! mkdir ${rundir}; then |
| 34 |
n=1 |
| 35 |
while ! mkdir ${rundir}_${n} |
| 36 |
do |
| 37 |
n=$((n+1)) |
| 38 |
done |
| 39 |
rundir=${rundir}_${n} |
| 40 |
fi |
| 41 |
|
| 42 |
echo $rundir |