a.sh쉘 스크립트를 통해 변수를 어떻게 내 보냅니 까?
#! /bin/sh
export x=/usr/local
우리는 명령 줄에서 source ./a
을 할 수 있습니다. 하지만 쉘 스크립트를 통해 내보내기를 수행해야합니다. 명령 줄에서
b.sh
#! /bin/sh
. ~/a.sh
오류없이 ...하지만 $x
아무것도 표시되지 않습니다. 그래서 수출을 얻지 못했습니다.
어떻게 만들 수 있습니까? 자식 쉘의
쉘 스크립트는 자식 쉘 프로세스에서 실행되기 때문에 당신은 쉘 스크립트를 통해 수출을 할 수 없습니다
#! /bin/sh
export x=/usr/local
-----------
[email protected]: ./a.sh
[email protected]: echo $x
[email protected]: <insert ....>
관련 : http://superuser.com/questions/176783/what-is-the-difference-between-executing-a-bash-script-and-sourcing-a-bash-scrip#176788 – lesmana