source cmd

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.