为什么你的 shell 的初始化文件没有加载?
与大多数事情一样,这取决于™
我最近遇到了同样的现象,并通过以下练习来解决它:
我使用 iTerm。 iTerm 默认运行一个登录 shell。在 iTerm Preferences > General > Command > (*) Login Shell 中验证
因此,我知道 ~/.bash_profile 总是会被调用。
知道了这一点,我将以下内容放入我的 ~/.bash_profile 文件中:
for file in ~/.{bashrc,bash_exports,bash_aliases,bash_functions}; do
[ -r "$file" ] && source "$file"
done
unset file
请注意,我为 .bashrc、.bash_exports 等使用单独的文件。它使事情分开且简单。
还要注意 /etc/profile 是首先加载的,但由于我从未使用过该系统范围的 init 文件,我知道这不是我的问题。详情请查看$ man bash
所以,我从 ~/.bash_profile 文件开始。
我发现当我安装 Canopy Express 时,它的安装程序将我的 ~/.bash_profile 文件的内容替换为以下内容:
# Added by Canopy installer on 2017-04-19
# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make the bash prompt show that Canopy is active, otherwise 1
alias activate_canopy="source '/Users/lex/dev/python/User/bin/activate'"
# VIRTUAL_ENV_DISABLE_PROMPT=1 source '/Users/lex/dev/python/User/bin/activate'
附言Canopy 是一款出色的免费 python IDE,我强烈推荐。
幸运的是,我备份了我的 ~/.bash* 文件,因此恢复起来很容易且快速地解决了我的问题。
我的建议是了解对初始化文件的调用顺序,并从第一个文件开始,逐步解决,直到找到问题为止。
哦,您可能想验证您使用的是哪个 shell(我使用 bash):
~ $ echo $SHELL
/usr/local/bin/bash