스크립트
shell script EOF(End Of File) 사용하기
변군이글루
2022. 10. 19. 16:42
반응형
shell script EOF(End Of File) 사용하기
리눅스 쉘 스크립트에서 EOF (End Of File) 또는 "Here Document"를 사용하면 스크립트 내에서 멀티라인 텍스트 블록을 정의할 수 있습니다. 이것은 주로 스크립트에서 파일이나 명령에 데이터를 전달할 때 유용합니다.
덮어쓰기(파일이 없으면 생성됨)
file1.txt
cat <<EOF > file1.txt
hello
world
EOF
$ cat file1.txt
hello
world
file2.txt
cat <<'EOF' | sed 's/l/e/g' > file2.txt
Hello
World
EOF
$ cat file2.txt
Heeeo
Wored
file3.txt
cat > file3.txt <<EOF
hello
world
EOF
$ cat file3.txt
hello
world
728x90
추가(파일 끝에 붙이기)
file5.txt
cat <<EOF >> file5.txt
hello
world
EOF
cat <<EOF >> file5.txt
hello
world
EOF
$ cat file5.txt
hello
world
hello
world
file6.txt
cat >> file6.txt << EOF
hello
world
EOF
cat >> file6.txt << EOF
hello
world
EOF
$ cat file6.txt
hello
world
hello
world
728x90
반응형