#TIL #unix 파일 생성에 sudo 권한이 필요하면 tee

$ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

Installation on CentOS - docker 페이지에서 발견. tee 명령어(command)는 뭐고 EOF 문자는 뭔가?

$ echo hello tee | tee output.txt
hello tee
$ cat output.txt
hello tee

난 약자인 줄 알았는데, T 파이프에서 따온 이름이다. input이 하나고 output은 stdout, file 이렇게 두 개로 나간다. 얼~ 이름 잘 지었다. file을 여러 개 지정할 수 있어서 정확히는 두 개 이상이다.

EOF 문자는 here documents 리터럴(literal)이다. EOF는 delimiter일 뿐이다. 다른 문자로 해도 상관없음.

<<- 리다이렉션(redirection) 연산자(operator)는 leading tab을 제거해준다. 가독성을 위해 tab을 넣은 경우에 사용하면 요긴. leading tab도 없는데 <<- 연산자를 사용한 이유는 모르겠다.

파일 만들면 되는 거잖아. 왜 tee 명령어를 사용했을까? stdout도 필요 없는데.

sudo is unable to pipe the standard output to a file.

- tee (command) / wikipedia

그렇구나. 파일 생성에 sudo 권한이 필요할 때, tee 명령어를 사용하면 된다.

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

A Random Post