我已经使用 bash 两年了,刚刚尝试通过自制软件在我的 OS X 上切换到 zsh shell。我将我的默认(登录)shell 设置为 zsh,并通过查看当我启动终端时默认使用的 zsh shell 来确认它已正确设置。
但是,当我尝试从 zsh 中进入 bash shell 时,它似乎没有加载 ~/.bash_profile
,因为我无法使用在我的 中定义的别名运行我的命令~/.bash_profile
like alias julia="~/juila/julia"
等。另外,提示不是我在文件中设置的,而是返回 bash- 3.2$
.
出于某些原因,当我将登录 shell 设置为 bash,并从 bash 中输入 zsh 时,~/.zshrc
会正确加载。
那么,为什么每当我从 zsh 中运行 bash
时它都没有加载?我的 ~/.bash_profile
符号链接(symbolic link)到 ~/Dropbox/.bash_profile
以便与我的其他计算机同步。也许它会导致问题?
最佳答案
打开~/.zshrc
,在文件的最底部,添加以下内容:
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile;
fi
每次打开终端时,它都会加载 ~/.bash_profile
中定义的任何内容(如果该文件存在)。有了它,您可以保留 zsh 的自定义设置(颜色等)。您可以将自定义 shell 设置保存在 .bash_profile
文件中。
这比使用 bash -l
IMO 更干净。
如果您喜欢将设置放在 .bashrc
、.bash_login
或 .profile
中,您可以对它们执行相同的操作。
同样,您也可以将通用配置文件设置移动到单独的文件,即 .my_common_profile
,并将以下内容添加到 .bash_profile
和 .zshrc
:
if [ -f ~/.my_common_profile ]; then
. ~/.my_common_profile;
fi
关于bash - 从 zsh 进入 bash 时如何加载 ~/.bash_profile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23233603/