bash - 从 zsh 进入 bash 时如何加载 ~/.bash_profile?

标签 bash macos shell zsh zshrc

我已经使用 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/

相关文章:

linux - 需要 bash 帮助的初学者

bash - 如何以空格分隔的字符串形式获取 `find`的输出?

macos - 如何在 NSPopupButton 项目中显示图像和文本

c - VT100 数字键盘使用修饰符(ctrl/shift/alt)时的转义码

shell - 当我更新 oh-my-zsh 时出现错误。我该如何解决?

linux - "source script.sh"和 "./script.sh"有什么区别?

bash - unix:循环查找命令的结果

linux - 将 STDerr 和 STDout 放入 bash 脚本内的日志文件中

linux - $ 可以用作 BASH 中的连接符号吗?

c++ - 优胜美地 g++ : error: unrecognized command line option '-Xarch_x86_64' 上的 capybara-webkit