Only try to create the subdir if does not already exist

Signed-off-by: Christian König <ckoenig@posteo.de>
This commit is contained in:
Christian König
2022-08-02 00:02:13 +02:00
parent fb40a81146
commit 5f83ba9ff8
+14 -2
View File
@@ -37,8 +37,20 @@ unset IFS
old_path="."
for dir in "${path[@]}"; do
sftp -b - "${USER}"@"${HOST}" <<< "cd ${old_path}
-mkdir ${dir}"
mapfile -t dir_content <<< "$(
sftp -b - "${USER}"@"${HOST}" <<< "cd ${old_path}
ls -1"
)"
# Only try to create the subdir if does not already exist
if [[ "${dir_content[*]}" =~ "${dir}" ]]; then
echo "Dir: ${old_path}/${dir} already exists"
else
echo "Creating dir: ${old_path}/${dir}"
sftp -b - "${USER}"@"${HOST}" <<< "cd ${old_path}
-mkdir ${dir}"
fi
old_path="${old_path}/${dir}"
done