如何从命令行重新加载文件.bash_profile ?

通过退出并重新登录,我可以让shell识别对.bash_profile的更改,但我希望能够按需执行。


当前回答

Use

alias reload!=". ~/.bash_profile"

或者如果想通过函数添加日志:

function reload! () {
    echo "Reloading bash profile...!"
    source ~/.bash_profile
    echo "Reloaded!!!"
}

其他回答

保存.bash_profile文件 输入cd进入用户的主目录 使用.bash_profile重新加载配置文件

你只需要打字。~ / . bash_profile。

参考“源”做什么?。

如果您不介意丢失当前shell终端的历史记录,也可以这样做

bash - l

这将分叉您的shell并打开bash的另一个子进程。-l参数告诉Bash作为登录shell运行。这是必需的,因为.bash_profile不会作为非登录shell运行。欲了解更多信息,请阅读此处。

如果你想完全替换当前的shell,你还可以做:

执行bash -l

上面的代码不会分叉你当前的shell,而是完全替换它,所以当你输入exit时,它会完全终止,而不是让你回到上一个shell。

只需输入source ~/.bash_profile。

或者,如果你喜欢节省按键,你也可以打字。~ / . bash_profile。

如果.bash_profile文件不存在,可以尝试执行以下命令:

. ~/.bashrc

or

source ~/.bashrc

而不是。bash_profile。

您可以找到关于bashrc的更多信息。