아래 코드의 두 번째 줄에 ShellCheck 경고 [SC2045]가 표시됩니다. 마지막으로 ls
을 시도하기 전에 디렉터리가 비어 있지 않은지 확인하는대로 무시해도됩니까?ShellCheck 경고 : "ls 출력 반복 반복이 쉽지 않습니다. [SC2045]"
if [ "$(ls -A "$retryDir")" ] ; then
for thisRetryFile in $(ls "$retryDir"/*.tar.gz) ; do
scp -o ConnectTimeout=30 "$thisRetryFile" \
"[email protected]$remoteHost:$remotePath" >> "$BACKUPLOG"
done
fi
UPDATE : 후 주석을 읽은 후. 회선을 다음으로 변경했습니다 :
for thisRetryFile in "$retryDir"/*.tar.gz ; do
경고를 삭제했습니다.
보기 [BashPitfall # 1 (http://mywiki.wooledge.org/BashPitfalls#for_i_in_.24.28ls_.2A.mp3.29). – randomir
빈 디렉토리 만 문제는 아닙니다. 공백이있는 파일 이름도 문제가됩니다. – Barmar
[이유는 무엇입니까?] (https://unix.stackexchange.com/questions/128985/why-not-parse-ls) – Barmar