Unix проблема скрипта оболочки с пробелом в имени файла - PullRequest
0 голосов
/ 29 января 2020

Я новичок в сценариях оболочки. У нас есть требование написать сценарий оболочки для требования ниже. Мы будем ежедневно получать файлы в следующем формате. 1. / app / dstage / BAL / Activ Bal_pen_20200129.xls
2. / app / dstage / BAL / Activ Bal_pen_20200130.xls
3. / app / dstage / BAL / Activ Bal_pen_20200131.xls Нам нужно написать сценарий оболочки, как только файлы попадают в директорию>, мне нужно переместить их в другой промежуточный каталог. Я пишу ниже сценарий. Однако я получаю сообщение, файл не найден, даже файл "Activ Bal_pen_20200129.xls" присутствует в каталоге. Я вижу проблему с пробелом в имени файла. Как решить проблему с пространством в имени файла. Мой скрипт ниже:

#!/bin/ksh
# Validation the number of arguments
if (( $# == 4 )); then
   Pattern=$1
   numFilesExpected=$2
   stgDir=$3
   maxWaitTime=$4
else
   print -u2 "Wrong number of arguments (${#}): Usage FileValidation.ksh <Pattern> <numFilesExpected> <stgDir> <maxWaitTime>"
   return 8
fi

# While max waiting duration is not obtained find files and set the array containing the file names; closing STDERR in case no files are found
waitTime=0

while (( $waitTime < $maxWaitTime )) ; do
        set -A fileList $(ls $Pattern 2<&-)

   if (( ${#fileList[@]} != 0 )); then
      break
   fi

   sleep 5
   ((waitTime++))
done

# Resetting the fileList in case it did not go in the loop
set -A fileList $(ls $Pattern 2<&-)

# Verifying if the pattern returned a file
if (( ${#fileList[@]} == 0 )); then
   print -u2 "No file found with pattern: $Pattern"
   return 1

#
elif [[ $(basename "$Pattern") = "*" ]]; then
   print -u2 "Found a source file pattern with no prefix (only a path with wildcard *): $Pattern"
   return 1

# Validation of the number of files expected
elif (( $numFilesExpected != 0 && ${#fileList[@]} != $numFilesExpected )); then
   print -n "${#fileList[@]}"
   return 2
fi
...