【发布时间】:2011-06-04 05:42:42
【问题描述】:
如何从命令行重新加载
.bash_profile?
我可以让 shell 通过退出并重新登录来识别对 .bash_profile 的更改,但我希望能够按需进行。
【问题讨论】:
标签: bash shell command-line
如何从命令行重新加载
.bash_profile?
我可以让 shell 通过退出并重新登录来识别对 .bash_profile 的更改,但我希望能够按需进行。
【问题讨论】:
标签: bash shell command-line
只需输入source ~/.bash_profile
或者,如果您喜欢保存击键,您可以输入. ~/.bash_profile
【讨论】:
alias BASHRELOAD=". ~/.bash_profile" 怎么样。如果您经常这样做,您可以将其别名为br。
alias reload='source ~/.bash_profile && echo "File .bash_profile reloaded correctly" || echo "Syntax error, could not import the file"';
. ~/.bash_profile
只要确保你对那里的当前状态没有任何依赖。
【讨论】:
.命令是什么?
. 只是source 命令的别名。
. 比 source 早。
source 是 . 的 bash 特定实现
. 和 source 在 bash 中实际上是一回事。来自链接:“source 是 bash 中点/句点 '.' 的同义词,但在 POSIX sh 中不是,因此为了获得最大的兼容性,请使用句点。”
您还可以使用此命令为该用户重新加载 ~/.bash_profile。确保使用破折号。
su - username
【讨论】:
cd 转到用户的主目录. .bash_profile重新加载配置文件【讨论】:
cd 回家吧。不需要~。
cd - 你可以从你当前所在的目录重新加载它:. ~/.bash_profile
简单输入:
. ~/.bash_profile
但是,如果您希望在终端启动时自动运行它而不是每次打开终端时都运行它,您可以将. ~/.bash_profile 添加到~/.bashrc 文件中。
注意:
当您打开终端时,终端会以(非登录)交互模式启动 bash,这意味着它将 source ~/.bashrc。
~/.bash_profile 仅在 交互式登录模式 启动时由 bash 获取。这通常仅在您登录控制台时(Ctrl+Alt+F1..F6),或通过ssh连接。
【讨论】:
将alias bashs="source ~/.bash_profile" 添加到您的 bash 文件中。
所以下次你可以拨打bashs
【讨论】:
reset -- 更容易记住
如果 .bash_profile 不存在,您可以尝试运行以下命令:
. ~/.bashrc
或
source ~/.bashrc
而不是 .bash_profile。 你可以找到更多关于bashrc的信息
【讨论】:
【讨论】:
我使用 Debian,我可以简单地输入 exec bash 来实现这一点。我不能说它是否适用于所有其他发行版。
【讨论】:
. .bash_profile 即可完成这项工作。与上面 7urkm3n 的回复相同。
我正在运行 Sierra,并为此工作了一段时间(尝试了所有推荐的解决方案)。我变得困惑,所以最终尝试重新启动我的电脑!成功了
我的结论是有时需要硬重置
【讨论】:
我想发布一个快速答案,即在使用 source ~/.bash_profile 或上述答案有效时,需要提及的一件事是,这只会在您正在查看的当前选项卡或会话中重新加载您的 bash 配置文件。如果您希望在每个选项卡/shell 上重新加载 bash 配置文件,则需要在每个选项卡/shell 中手动输入此命令。
如果您使用iTerm, you can use CMD⌘+Shift+I to enter a command into all current tabs。对于终端,引用此issue 可能很有用;
【讨论】:
alias reload!=". ~/.bash_profile"
或者如果想通过函数添加日志
function reload! () {
echo "Reloading bash profile...!"
source ~/.bash_profile
echo "Reloaded!!!"
}
【讨论】:
. ~/. bash_profile 或 source ~/.bash_profile
你只需要输入. ~/.bash_profile
参考:https://superuser.com/questions/46139/what-does-source-do
【讨论】:
如果您不介意丢失当前 shell 终端的历史记录,您也可以这样做
bash -l
这将分叉你的 shell 并打开另一个 bash 子进程。 -l 参数告诉 bash 作为登录 shell 运行,这是必需的,因为 .bash_profile 不会作为非登录 shell 运行,有关此read here 的更多信息
如果你想完全替换当前的 shell 你也可以这样做:
exec bash -l
上面的代码不会派生你当前的shell,而是完全替换它,所以当你输入exit时,它会完全终止,而不是让你回到以前的shell。
【讨论】: