source是執行一個文件在當前shell中生效, 而用./filename或者sh filename 都是相當於額外開一個shell執行(執行結果在當前shell中不生效) 所以一般用戶配置文件生效方式會採用 source ~/.bash_profile。
測試方法:
編寫tmp.sh 內容爲export test=2, 使用sh tmp.sh 時, echo $test爲空, 使用source tmp.sh 時, echo $test結果爲2.
source是執行一個文件在當前shell中生效, 而用./filename或者sh filename 都是相當於額外開一個shell執行(執行結果在當前shell中不生效) 所以一般用戶配置文件生效方式會採用 source ~/.bash_profile。
測試方法:
編寫tmp.sh 內容爲export test=2, 使用sh tmp.sh 時, echo $test爲空, 使用source tmp.sh 時, echo $test結果爲2.