`

ubuntu 下环境变量设置注意事項

 
阅读更多

今天在设置环境变量时,发现了一个很诡异的地方:

  当我修改了变量后,进行source后,再执行命令,发现还是用旧的命令来执行。

 

跟下去发现,当用env时,当中的PATH变长了,而且刚设置的新变量附到最后。对了!就是这样ubuntu下如果PATH下有相同的shell-file时,它只对最初的file有效,而我设置PATH=$new-property:$PATH,所以造成了这样的結果。

 

小结:

-在环境变量设置中要将原来的变量名称附加到最后,而不是最前;

-使用source后,它会依据当前的变量k-v值添加到访k中。如

  p1=$new-val:$p1

 它会将上次的p1值重新添加上去;

 其实source 也称为“点符号",因为它与" . file"功能是一样的;

-source只是在当前shell terminal有效,如果退出将失效。所以如果要想修改profile等后要在所有terminal生效,必须注销才行。

 

reference from “man builtins" command:

source filename [arguments]
              Read and execute commands from filename in the current shell environment and return the exit status of the last command executed from file‐
              name.

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics