![구분 기호가 없는 여기 문서](https://linux55.com/image/135378/%EA%B5%AC%EB%B6%84%20%EA%B8%B0%ED%98%B8%EA%B0%80%20%EC%97%86%EB%8A%94%20%EC%97%AC%EA%B8%B0%20%EB%AC%B8%EC%84%9C.png)
존재하다이 게시물, Stephen의 답변은 다음 코드를 보여줍니다.
cat <<-"EOF1" >> myPath/myFile.append
if ! grep -F -q -f myPath/myFile{.append,}; then
cat myPath/myFile.append >> myPath/myFile
fi
여기 문서에 구분 기호가 없는 이유는 무엇입니까?
답변1
내가 테스트한 모든 쉘은 문서를 잘 읽었으며 종결자가 없어도 문서는 파일 끝에서 끝났습니다. Bash는 이에 대해 경고하지만 busybox/dash/ksh 및 zsh는 이를 자동으로 처리합니다.
예를 들어
$ cat heredoctest.sh
#!/bin/bash
cat -n <<EOF
foo
bar
$ bash heredoctest.sh
heredoctest.sh: line 4: warning: here-document at line 2 delimited by end-of-file (wanted `EOF')
1 foo
2 bar
하지만 제공하신 특정 코드 예제는 버그인 것 같습니다. 작성된 대로 if 문만 추가하므로 myPath/myFile.append
별로 유용해 보이지 않습니다. here-doc 콘텐츠와 종결자가 cat
와 사이에서 사라진 것 같습니다 if
.