리눅스 cat <<EOT

Jmnote (토론 | 기여)님의 2020년 9월 29일 (화) 00:14 판 (Jmnote님이 리눅스 cat ≪EOT 문서를 리눅스 cat ≪EOF 문서로 이동했습니다)

1 개요

리눅스 cat <<EOT
  • Bash 쉘에서 HEREDOC 구문의 전형적인 형식
  • 직접 입력한 텍스트를 파일에 저장할 때 주로 사용한다.
  • 시작 및 종료를 알리는 키워드로는 흔히 EOT 또는 EOF를 쓰는데, 임의로 정하는 것이므로 다른 것(예: AAA, HELLO)도 가능하다.
EOT는 End of Text, EOF는 End of File이라는 의미이다.
쉘에서 실행
cat <<EOT > file1.txt
hello
world
EOT
user01@localhost:~$ cat <<EOT > file1.txt
> hello
> world
> EOT
user01@localhost:~$ cat file1.txt
hello
world
쉘에서 실행 2
cat > file2.txt <<ZZZ 
hello
world
ZZZ
user01@localhost:~$ cat > file2.txt <<EOT
> hello
> world
> EOT
user01@localhost:~$ cat file2.txt 
hello
world
스크립트에서 실행
user01@localhost:~$ cat a.sh
cat <<EOT > file3.txt
hello
world
EOT
user01@localhost:~$ sh a.sh
user01@localhost:~$ cat file3.txt
hello
world

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}