如何从命令行重新加载.bash_profile
?我可以通过退出并重新登录来使 Shell 识别对.bash_profile
的更改,但我希望能够按需进行操作。
只需输入source ~/.bash_profile
另外,如果您喜欢保存击键,则可以键入. ~/.bash_profile
. ~/.bash_profile
. ~/.bash_profile
su - username
. !$
cd
转到用户的主目录. .bash_profile
如果您不介意丢失当前 Shell 终端的历史记录,也可以这样做
bash -l
那将分叉您的外壳并打开 bash 的另一个子进程。 -l
参数告诉 bash 作为登录 shell 运行,这是必需的,因为. bash_profile 不会作为非登录 shell 运行,有关更多信息, 请参见此处
如果要完全替换当前的外壳,也可以执行以下操作:
exec bash -l
上面的内容不会派生您的当前 shell,而是将其完全替换,因此,当您键入exit
,它将完全终止,而不是将您放到上一个 shell。
在您的 bash 文件中添加alias bashs="source ~/.bash_profile"
。所以你下次可以打bashs
您只需要输入即可. ~/.bash_profile
参考: https : //superuser.com/questions/46139/what-does-source-do
. ~/.bashrc
source ~/.bashrc