"리눅스 cat ≪EOF"의 두 판 사이의 차이

9번째 줄: 9번째 줄:
{{소스헤더|쉘에서 실행}}
{{소스헤더|쉘에서 실행}}
<source lang='bash'>
<source lang='bash'>
cat <<EOT > file1.txt
cat <<EOF > file1.txt
hello
hello
world
world
EOT
EOF
</source>
</source>
<source lang='console'>
<source lang='console'>
user01@localhost:~$ cat <<EOT > file1.txt
user01@localhost:~$ cat <<EOF > file1.txt
> hello
> hello
> world
> world
> EOT
> EOF
user01@localhost:~$ cat file1.txt
user01@localhost:~$ cat file1.txt
hello
hello
32번째 줄: 32번째 줄:
</source>
</source>
<source lang='console'>
<source lang='console'>
user01@localhost:~$ cat > file2.txt <<EOT
user01@localhost:~$ cat > file2.txt <<EOF
> hello
> hello
> world
> world
> EOT
> EOF
user01@localhost:~$ cat file2.txt  
user01@localhost:~$ cat file2.txt  
hello
hello
44번째 줄: 44번째 줄:
<source lang='console'>
<source lang='console'>
user01@localhost:~$ cat a.sh
user01@localhost:~$ cat a.sh
cat <<EOT > file3.txt
cat <<EOF > file3.txt
hello
hello
world
world
EOT
EOF
user01@localhost:~$ sh a.sh
user01@localhost:~$ sh a.sh
user01@localhost:~$ cat file3.txt
user01@localhost:~$ cat file3.txt

2020년 9월 29일 (화) 00:15 판

1 개요

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

2 같이 보기

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