
shell script
스크립트의 해당 부분을 실행하기 전에 텍스트 파일에 이름이 추가되었는지 확인하는 기능이 있습니다 . 이름을 찾으면 스크립트의 이 부분을 건너뜁니다.
다음은 충돌의 예입니다.
네덜란드 령 앤 틸리 스
if ! grep "netherlands-antilles" uploaded.txt; then
// Do some work here
echo netherlands-antilles >> uploaded.txt
fi
네덜란드
if ! grep "netherlands" uploaded.txt; then
// Do some work here
echo netherlands >> uploaded.txt
fi
이미 텍스트 파일에 있기 때문에 Netherlands Antillies
실제로 필요한 스크립트의 "네덜란드" 부분을 실행하지 않습니다.
grep
문자열의 일부만 검색 하지 않는 방법이 있나요 ? netherlands
일치하는 항목을 검색하고 싶지 않습니다 netherlands-antilles
.
답변1
이러한 항목이 파일 줄의 유일한 내용인 경우 정규식을 사용하여 줄의 시작과 줄의 enf를 포함할 수 있습니다.
if ! grep "^netherlands$" uploaded.txt; then
// Do some work here
echo netherlands >> uploaded.txt
fi