請問shell script中export環境變數的問題 - Linux

Table of Contents


要有 父子行程 的觀念,子行程可以繼承父行程的環境變數,
反之則否。

所以,你的例子是錯誤的,你可以改成。

#script2
export PORT=Linux
echo $PORT
#end of file

==================

#script1
PORT=`./script2`
echo $PORT
#end of file

或者,把 export 宣告放在 script1 (父行程),
script2 (子行程) 再去使用就可以了。


※ 引述《wahoho (..)》之銘言:
: 如果現在有兩個script
: script1和script2
: 內容分別是
: #script2
: export PORT=Linux
: #end of file
: =============
: #script1
: ./script2
: echo $PORT
: #end of file
: 請問有辦法讓script2中export的變數繼續存在script1裡面嗎?

--

I'm root.

--

All Comments