![텍스트 파일의 고유한 내용을 동일하게 등록되지 않은 예상 문자열과 비교합니다.](https://linux55.com/image/218670/%ED%85%8D%EC%8A%A4%ED%8A%B8%20%ED%8C%8C%EC%9D%BC%EC%9D%98%20%EA%B3%A0%EC%9C%A0%ED%95%9C%20%EB%82%B4%EC%9A%A9%EC%9D%84%20%EB%8F%99%EC%9D%BC%ED%95%98%EA%B2%8C%20%EB%93%B1%EB%A1%9D%EB%90%98%EC%A7%80%20%EC%95%8A%EC%9D%80%20%EC%98%88%EC%83%81%20%EB%AC%B8%EC%9E%90%EC%97%B4%EA%B3%BC%20%EB%B9%84%EA%B5%90%ED%95%A9%EB%8B%88%EB%8B%A4..png)
어떤 ".err" 텍스트 파일이 비어 있는지 확인하기 위해 쉘 스크립트를 작성했습니다. 일부 파일에는 다음 예제 파일과 같이 특정 반복 문구가 있습니다 fake_error.err
(의도적으로 사용된 빈 줄).
WARNING: reaching max number of iterations
WARNING: reaching max number of iterations
WARNING: reaching max number of iterations
WARNING: reaching max number of iterations
WARNING: reaching max number of iterations
WARNING: reaching max number of iterations
WARNING: reaching max number of iterations
WARNING: reaching max number of iterations
WARNING: reaching max number of iterations
빈 파일 외에 삭제하고 싶습니다. 이를 위해 다음 스크립트를 작성했습니다.
#!/bin/bash
for file in *error.err; do
if [ ! -s $file ]
then
echo "$file is empty"
rm $file
else
# Get the unique, non-blank lines in the file, sorted and ignoring blank space
lines=$(grep -v "^$" "$file" | sort -bu "$file")
echo $lines
EXPECTED="WARNING: reaching max number of iterations"
echo $EXPECTED
if [ "$lines" = "$EXPECTED" ]
then
# Remove the file that only has iteration warnings
echo "Found reached max iterations!"
rm $file
fi
fi
done
그러나 파일에서 실행될 때 이 스크립트의 출력은 다음 fake_error.err
과 같습니다.
WARNING: reaching max number of iterations
WARNING: reaching max number of iterations
루프의 두 문에서 실행 $echo
되지만 파일 자체는 삭제되지 않고 "Found reached max iterations!"
문자열도 인쇄되지 않습니다. 문제는 if [ "$lines" = "$EXPECTED" ]
이중 괄호를 사용해 보았지만 작동하지 않는다는 것입니다 [[ ]]
. ==
나는 이 두 가지 인쇄된 진술의 차이점이 무엇인지 모르겠습니다.
두 변수가 동일하지 않은 이유는 무엇입니까?