[Linux] Here Documents(<<), Here Strings(<<<)

HYEOB KIM·2022년 8월 19일
1

Linux

목록 보기
8/11

Here Documents(<<)

입력 리디렉션의 일종으로 파일로부터 입력을 받는 < 입력 리디렉션이 아닌 명령줄을 통해 직접 여러 줄을 입력 받을 수 있는 입력 리디렉션 방법입니다.

$ wc << EOF
> HELLO
> HI
> HELLO WORLD
> EOF

cat 명령어와 출력 리디렉션을 응용하는 방법은 아래와 같습니다. 스크립트를 작성할 때 이 방법이 상당히 유용하게 쓰일 수 있습니다.

$ cat > hellotext << EOF
> hello world
> hi
> hello
> EOF

$ cat hellotext
hello world
hi
hello

Here Strings(<<<)

Here documents의 한 줄 버전

$ cat > hellotext <<< "hello world there"

$ cat hellotext
hello world there

echo를 이용해서 출력 리디렉션을 이용하는 방법이 훨씬 유용하게 쓰이긴 합니다.

$ echo "hello world there" > hellotext

$ cat hellotext
hello world there
profile
Devops Engineer

0개의 댓글