read

쉘스크립트를 만들때, 정해진 입력값들을 설정해두고 싶을 때가 있다. 예를들어 ftp 명령을 실행하고 나서, a.txt 를 업로드 하는 쉘스크립트를 만든다고 하자.

#!/bin/bash
ftp server.address.com -u anonymous -p somepasswd

이렇게 해서 ftp 연결이 됐으면 이번엔 'put a.txt' 라는 명령을 ftp 에다가 전달해야 될 차례이다. 이럴 때 사용할 수 있는 것인 << redirection 이다. 사용법은 아래와 같다.

#!/bin/bash
ftp server.address.com -u anonymous -p somepasswd << TEST_TAG
put a.txt
TEST_TAG

<< redirection 은 그 뒤의 태그만 적힌 줄을 만나기 전까지 source 의 내용을 해당 명령의 stdin 으로 전달한다. 그러니까 ftp 명령을 실행하고, 'put a.txt' 를 수행한다. 그 다음 만나는 줄은 TEST_TAG 니까 redirection 이 종료된다. 출처 : http://www.daniweb.com/software-development/shell-scripting/threads/50570

Blog Logo

Ki Sung Bae


Published

Image

Gsong's Blog

Developer + Entrepreneur = Entreveloper

Back to Overview