#TIL #bash 스크립트에서 here document로 긴 파일을 쉽게 만드는 법

cat << EOF > /tmp/yourfilehere
These contents will be written to the file.
        This line is indented.
EOF

here document라고 한다. EOF 사이에 내용을 분리된 파일처럼 취급한다. 즉 here document 내용을 cat 명령어로 stdout으로 출력한다. 출력 내용을 리다이렉션 연산자를 써서 파일로 저장한다.

한두 줄이면 리다이렉션 연산자로 파일을 만들어도 괜찮다. 하지만 길면 줄을 맞춘다고 해도 괴롭다. 이럴 때, here document를 요긴하게 쓸 수 있다.

참고 - How can I write a heredoc to a file in Bash script? - stackoverflow.com

Feedback plz <3 @ohyecloudy, ohyecloudy@gmail.com

A Random Post