while read newfile <&3; do
if [[ ! $newfile =~ [^[:space:]] ]] ; then #empty line exception
continue
fi
#
while read oldfile <&3; do
if [[ ! $oldfile =~ [^[:space:]] ]] ; then #empty line exception
continue
fi
echo Comparing "$newfile" with "$oldfile"
#
if diff "$newfile" "$oldfile" >/dev/null ; then
echo The files compared are the same. No changes were made.
else
echo The files compared are different.
fi
done 3</infanass/dev/admin/oldfiles.txt
done 3</infanass/dev/admin/newfiles.txt
이것은 중첩 된 루프를 수행하는 올바른 방법이라고 생각합니다.하지만 제대로 작동하지 않습니다.
그런 파일 설명자 3을 사용할 필요가 없습니다.
while read newfile do
if [[ ! $newfile =~ [^[:space:]] ]] ; then #empty line exception
continue
fi
while read oldfile ; do
if [[ ! $oldfile =~ [^[:space:]] ]] ; then #empty line exception
continue
fi
echo Comparing "$newfile" with "$oldfile"
# diff -q doesn't bother generating a diff.
# It just tells you whether or not the files match.
if diff -q "$newfile" "$oldfile" >/dev/null ; then
echo The files compared are the same. No changes were made.
else
echo The files compared are different.
fi
done < /infanass/dev/admin/oldfiles.txt
done < /infanass/dev/admin/newfiles.txt
빈 줄이 공백 만있는 줄이라고 가정하면 빈 줄 예외 코드는 비어 있지 않은 줄과 일치 할 수 있습니다. 공백 만있는 줄과 일치합니다 ( \s*
완전히 빈 줄만 일치 시키려면 제거 ) :
if [[ ! $newfile =~ ^\s*$ ]] ; then #empty line exception
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다