Why do I need to source bash_profile every time

こ雲淡風輕ζ 提交于 2019-12-03 13:58:45

问题


I have installed Hadoop and every time I want to run it, first I have to do this:

source ~/.bash_profile

or it won't recognize the command hadoop

Why is that?

I am on OSX 10.8


回答1:


Now that we've narrowed down the problem:

  1. Run ps -p $$ at the command line to determine that you are, in fact, using a bash shell.
  2. Realize that you are in zsh, which means you should be editing your profile in .zshrc.
  3. Copy the offending lines from .bash_profile to .zsh, OR
  4. Modify your .zshrc to directly source your .bash_profile.

UPDATE: Do what @TC1 mentions in the comments and keep the shell-specific code in each shell's own profile, and from those profiles, only source shell-agnostic code.




回答2:


I tried the approved answer. Changing the .zshrc file works for one of my machines. But for the other one, when I run ps -p $$, it is -sh under the command. And I changed both bash and zsh files, neither of them works for me this time.

So I found this https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html

it mentioned "When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. "

so I went to that file /etc/profile and add "source ~/.bashrc" in that file. Then it works since every time a terminal is opened, it runs the command in that /etc/profile file.



来源:https://stackoverflow.com/questions/15733508/why-do-i-need-to-source-bash-profile-every-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!