본문 바로가기

리눅스

[리눅스] shell script EOF(End Of File) 사용하기

728x90

shell script EOF(End Of File) 사용하기

덮어쓰기(파일이 없으면 생성됨)

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

추가(파일 끝에 붙이기)

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