关于ubuntu 11.04生成的.profile的问题
我注意到安装 Ubuntu 11.04 时生成的 ~/.profile
底部有以下几行:
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
我看到了那里的逻辑,但不应该导出 PATH 变量吗?
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
export PATH="$HOME/bin:$PATH"
fi
如果不是,那么我不明白一旦到达 .profile
文件的底部, PATH 的值如何不会丢失,除非有东西使用 获取该文件。 ~/.profile
,我没有看到(至少明确地)在系统上的任何其他 shell 脚本中发生这种情况。
I noticed the following lines at the bottom of my ~/.profile
that was generated from when I installed Ubuntu 11.04:
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
I see the logic there, but shouldn't the PATH variable be exported?
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
export PATH="$HOME/bin:$PATH"
fi
If not, then I don't understand how the value of PATH does not get lost once the bottom of the .profile
file is reached, unless something is sourcing this file with . ~/.profile
, which I do not see (at least explicitly) happening in any other shell script on the system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果变量已导出,则无需再次导出。是的,当您启动登录 shell 时,shell 会(道德上相当于)source
.profile
(除非您也有.bash_profile
;但是通常应该使用 source依次.profile
)。If a variable is already exported, you don't have to export it again. And yes, the shell does (the moral equivalent of) source
.profile
when you start a login shell (unless you also have a.bash_profile
; but then that should customarily source.profile
in turn).