我怎样才能重新加载.bash_profile
命令 </跨度> 线?我可以通过退出并重新登录来让shell识别对.bash_profile的更改,但我希望能够按需执行此操作。 锟斤拷
加 alias bashs=”source ~/.bash_profile” 进入你的bash文件。所以你可以打电话 bashs 从下次开始
alias bashs=”source ~/.bash_profile”
bashs
如果.bash_profile不存在,您可以尝试运行以下命令:
. ~/.bashrc </code>
. ~/.bashrc
</code>
要么 source ~/.bashrc</code> 而不是.bash_profile。您可以找到有关的更多信息 在.bashrc
要么
source ~/.bashrc</code>
source ~/.bashrc
而不是.bash_profile。您可以找到有关的更多信息 在.bashrc
只需输入:
. ~/.bash_profile</code>
. ~/.bash_profile
但是,如果您希望在终端启动时自动运行它而不是每次打开终端时都运行它,您可以添加 . ~/.bash_profile 至 ~/.bashrc 文件。 的 注意: </强> 当您打开终端时,终端以(非登录)交互模式启动bash,这意味着它将来源 ~/.bashrc 。 ~/.bash_profile 仅在启动时由bash提供 的 交互式登录模式 </强> 。这通常仅在您登录控制台时( 按Ctrl + Alt键 + F1 .. F6 ),或通过连接 ssh 。
但是,如果您希望在终端启动时自动运行它而不是每次打开终端时都运行它,您可以添加 . ~/.bash_profile 至 ~/.bashrc 文件。
~/.bashrc
的 注意: </强>
当您打开终端时,终端以(非登录)交互模式启动bash,这意味着它将来源 ~/.bashrc 。
~/.bash_profile 仅在启动时由bash提供 的 交互式登录模式 </强> 。这通常仅在您登录控制台时( 按Ctrl + Alt键 + F1 .. F6 ),或通过连接 ssh 。
~/.bash_profile
ssh
alias reload!=”. ~/.bash_profile”</code>
alias reload!=”. ~/.bash_profile”
或者如果想通过函数添加日志 function reload! () { echo “Reloading bash profile…!” source ~/.bash_profile echo “Reloaded!!!”}</code>
或者如果想通过函数添加日志
function reload! () { echo “Reloading bash profile…!” source ~/.bash_profile echo “Reloaded!!!”}</code>
function reload! () { echo “Reloading bash profile…!” source ~/.bash_profile echo “Reloaded!!!”}
我使用Debian,我可以简单地输入 exec bash 为达到这个。我不能说它是否适用于所有其他发行版。
exec bash
您也可以使用此命令为该用户重新加载〜/ .bash_profile。确保使用短划线。
su - username</code>
su - username
只需确保您对当前状态没有任何依赖关系。
你只需要输入 . ~/.bash_profile
参考: https://superuser.com/questions/46139/what-does-source-do
我正在运行Sierra,并且正在研究这个问题一段时间(尝试所有推荐的解决方案)。我变得困惑,所以最终尝试重新启动我的电脑!有效
我的结论是,有时需要进行硬重置
cd
. .bash_profile
我喜欢这样的事实:在您刚编辑完文件后,您需要做的就是键入:
. !$</code>
. !$
这会获取您刚刚在历史记录中编辑的文件。看到 什么是bash中的爆炸美元 。
只需输入 source ~/.bash_profile
source ~/.bash_profile
或者,如果您想保存击键,可以键入 . ~/.bash_profile
如果您不介意丢失当前shell终端的历史记录,您也可以这样做
bash -l
这会分叉你的shell并打开另一个bash的子进程。该 -l 参数告诉bash作为登录shell运行,这是必需的,因为.bash_profile不会作为非登录shell运行,有关此内容的更多信息 在这里阅读
-l
如果要完全替换当前shell,还可以执行以下操作:
exec bash -l
以上内容不会分叉您当前的shell,而是完全替换它,因此当您键入时 exit 它会完全终止,而不是让你掉到以前的shell。
exit