"Bash 자식스크립트에서 변수 받아와서 다른 자식스크립트에 변수 전달하기"의 두 판 사이의 차이

2번째 줄: 2번째 줄:
;Bash 자식스크립트에서 변수 받아와서 다른 자식스크립트에 변수 전달하기
;Bash 자식스크립트에서 변수 받아와서 다른 자식스크립트에 변수 전달하기


==방법 1: source + export==
{{소스헤더|parent.sh}}
{{소스헤더|parent.sh}}
<source lang='bash'>
<source lang='bash'>
23번째 줄: 24번째 줄:
echo foo=[$foo]
echo foo=[$foo]
echo bar=[$bar]
echo bar=[$bar]
</source>
{{소스헤더|실행결과}}
<source lang='console'>
$ ./parent.sh
-- child1 end...
-- child2 start...
foo=[hello]
bar=[world]
</source>
==방법 2: set -a==
{{소스헤더|parent.sh}}
<source lang='bash'>
#!/bin/bash
set -a
source child1.sh
./child2.sh
</source>
</source>
{{소스헤더|실행결과}}
{{소스헤더|실행결과}}

2018년 11월 15일 (목) 01:26 판

1 개요

Bash 자식스크립트에서 변수 받아와서 다른 자식스크립트에 변수 전달하기

2 방법 1: source + export

parent.sh
#!/bin/bash
source child1.sh
export foo
export bar
./child2.sh
child1.sh
#!/bin/bash
foo=hello
bar=world
echo -- child1 end...
child2.sh
#!/bin/bash
echo -- child2 start...
echo foo=[$foo]
echo bar=[$bar]
실행결과
$ ./parent.sh 
-- child1 end...
-- child2 start...
foo=[hello]
bar=[world]

3 방법 2: set -a

parent.sh
#!/bin/bash
set -a
source child1.sh
./child2.sh
실행결과
$ ./parent.sh 
-- child1 end...
-- child2 start...
foo=[hello]
bar=[world]

4 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}