develog

[linux] here document 본문

카테고리 없음

[linux] here document

냐옴 2024. 3. 13. 13:56

 

here document 문법
명령어 << EOF
    # 여기에 서브 명령어를 입력
EOF

 

<< 를 사용하면 블럭 안에 탭이 적용된다

 

# test.sh
cat << EOF
        aa
                bb
cc
EOF

실행결과

$ ./test.sh
        aa
                bb
cc

 

<<- 를 사용하면 블럭 안에 탭이 무시된다
# test.sh
cat <<- EOF
        aa
                bb
cc
EOF

실행결과

$ ./test.sh
aa
bb
cc

 

변수 사용, 명령어 실행

- 변수 사용 : ${}

- 명령어 실행 : $()

# test.sh

message="hello world"

cat <<- EOF
        # variable
        message=${message}

        # command
        date=$(date)
EOF

실행결과

$ ./test.sh
# variable
message=hello world

# command
date=Thu 14 Mar 2024 12:28:49 AM UTC

 

sftp 사용 예제
sftp user01@127.0.0.1 <<- EOF
  cd upload
  ls
  exit
EOF

 

Comments