【发布时间】:2017-02-07 14:09:22
【问题描述】:
我对我的 shell 如何读取 bash_profile 感到非常困惑。
在 root 中,我的 ~/.bash_profile 看起来像这样
# .bash_profile
# Get the aliases and functions
if [-f ~/.bashrc ]; then
.~/.bashrc
fi
PATH=$PATH:$HOME/bin:$HOME/sbin:$HOME/usr/sbin:$HOME/usr/bin:/usr/sbin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export PATH=$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH
unset USERNAME
没有 ~/.profile 文件。
在名为 maruhan 的用户中,我的 ~/.bash_profile 看起来像这样
# .bash_profile
# Get the aliases and functions
if [-f ~/.bashrc ]; then
.~/.bashrc
fi
PATH=$PATH:$HOME/bin:$HOME/sbin:$HOME/usr/sbin:$HOME/usr/bin:/usr/sbin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/maruhan/Desktop/issac:/usr/local/lib
ASDF=$ASDF:/home
export PATH=$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH
export ASDF=$ASDF
unset USERNAME
我的 ~/.profile 看起来像这样
LD_LIBRARY_PATH=/home/maruhan/Desktop/issac:/usr/local/lib:$LD_LIBRARY_PATH
ASDF=/home:$ASDF
export ASDF=$ASDF
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH
您可以清楚地看到,ASDF 没有在 root 的 bash_profile 中定义。
但是,当我调用 export 时,我会在 root 中得到这个。
declare -x ASDF=":/home"
但与 LD_LIBRARY_PATH 无关。
奇怪的是,在 maruhan 中,运行导出会同时显示 ASDF 和 LD_LIBRARY_PATH。
此外,/etc/environment 中没有任何关于 ASDF 或 LD_LIBRARY_PATH 的内容。我也没有 /etc/bash_profile 文件。
运行echo $0 给我bash 用于root 和maruhan。
为什么 LD_LIBRARY_PATH 在 ASDF 存在时在 root 中消失了?
【问题讨论】:
-
root 用户如何启动
bash?还有maruhan? -
@whjm 你能帮我检查一下吗?
-
export PATH LD_LIBRARY_PATH ASDF就足够了;您不需要“重新分配”这些值。export标记名称,而不是值。 -
@chepner 我知道。我不是 100% 确定,而且事情没有按预期进行,所以我把它放在那里以防万一。
-
@CuriousKimchi -- 更新了我的答案。