Improve deplay.sh script to check against exact matches instead of regex-matching the searched string against the entire collapsed array to avoid incorrect partial matches

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2023-05-21 09:32:41 +02:00
parent 25a1d06834
commit 6b531e7c27
No known key found for this signature in database
GPG Key ID: 00135ACBD90B28DD
1 changed files with 12 additions and 5 deletions

View File

@ -42,11 +42,18 @@ for dir in "${path[@]}"; do
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}"
# Loop over the dir content and check if this exact dir already exists
path_exists=0
for content in "${dir_content[@]}"; do
if [[ "${content}" == "${dir}" ]]; then
echo "Dir: ${old_path}/${dir} already exists"
path_exists=1
fi
done
# If the dir does not exist, create it
if [[ "${path_exists}" -eq 0 ]]; then
echo "Dir: ${old_path}/${dir} does not exist. Creating it."
sftp -b - "${USER}"@"${HOST}" <<< "cd ${old_path}
-mkdir ${dir}"
fi