bash macOS Catalina 10.15(beta) - 为什么 ~/.bash_profile 不是由我的 shell 提供的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/56784894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:38:48  来源:igfitidea点击:

macOS Catalina 10.15(beta) - Why is ~/.bash_profile not sourced by my shell?

bashshellenvironment-variableszshmacos-catalina

提问by Reza Dehnavi

I want to set the environment variable I added below the line to ~/.bash_profileand ~/.profilebut it didn't work.

我想设置我在该行下方添加的环境变量~/.bash_profile~/.profile但它不起作用。

export JBOSS_HOME=/Users/{USERNAME}/Desktop/jboss7

Afterward, exit the terminal and open it again when executing echo $JBOSS_HOMEI get nothing.
enter image description here

之后,退出终端并在执行时再次打开它echo $JBOSS_HOME我什么也没得到。
在此处输入图片说明

回答by fdg13gustav

Apple has changed the default shell to zsh. Therefore you have to rename your configuration files. .bashrcis now .zshrcand .bash_profileis now .zprofile.

Apple 已将默认 shell 更改为 zsh。因此,您必须重命名配置文件。.bashrc现在是.zshrc.bash_profile现在.zprofile

回答by Rostyslav Druzhchenko

If you for some reason (as me) don't want to rename/move your ~/.bash_profilefile you can do the next things:

如果您出于某种原因(如我)不想重命名/移动您的~/.bash_profile文件,您可以执行以下操作:

  1. Create a new file ~/.zprofile
  2. Type there source ~/.bash_profile
  3. Save and close
  4. Run a new terminal session
  1. 创建一个新文件 ~/.zprofile
  2. 在那里输入 source ~/.bash_profile
  3. 保存并关闭
  4. 运行一个新的终端会话

回答by ExoWanderer

I created a new file called

我创建了一个名为的新文件

/usr/local/bin/mybash

/usr/local/bin/mybash

which contains a wrapper script:

其中包含一个包装脚本:

/usr/local/bin/bash --init-file $HOME/.bashrc

/usr/local/bin/bash --init-file $HOME/.bashrc

I installed this local/bin/bash from HomeBrew.

我从HomeBrew安装了这个 local/bin/bash 。

Full Sequence of Events

完整的事件序列

brew install bash
echo "/usr/local/bin/bash --init-file $HOME/.bashrc" > /usr/local/bin/mybash
chmod +x /usr/local/bin/mybash

Then I opened the settings for terminal.app[cmd-comma]. Under the GeneralTab, select the radio button for Command (complete path)

然后我打开了terminal.app[cmd-comma]的设置。在General选项卡下,选择单选按钮Command (complete path)

In the text box change the text from /bin/zsh/to /usr/local/bin/bash.

在文本框中将文本从 更改/bin/zsh//usr/local/bin/bash

Example of final format

最终格式示例

回答by vikas kumar

changing the bash profile to zsh profile works and source it as well to see in action.

将 bash 配置文件更改为 zsh 配置文件可以工作并获取它以查看操作。

vikas@Vikas-Kumar ~ % mv .bash_profile .zsh_profile
vikas@Vikas-Kumar ~ % source .zsh_profile

回答by Gilberto

You can create a simbolic link and keep your .bash_profile file with this:

您可以创建一个符号链接并使用以下内容保留您的 .bash_profile 文件:

ln -s .bash_profile .zsh_profile
source .zsh_profile

Any changes in .bash_profile will be reflected in .zsh_profile

.bash_profile 中的任何更改都将反映在 .zsh_profile 中

回答by Maggie

cp zprofile ~/.zprofile

Add to .zprofile:

添加到.zprofile

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

eg. by >vi .zprofile

例如。经过>vi .zprofile

Done

完毕