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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4608187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 20:02:26  来源:igfitidea点击:

How to reload .bash_profile from the command line?

bashshellcommand-line

提问by markdorison

How can I reload .bash_profilefrom the command line?

我怎样才能重新加载.bash_profile命令行

I can get the shell to recognize changes to .bash_profileby exiting and logging back in but I would like to be able to do it on demand.

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

回答by SiegeX

Simply type source ~/.bash_profile

只需输入 source ~/.bash_profile

Alternatively, if you like saving keystrokes you can type . ~/.bash_profile

或者,如果你喜欢保存击键,你可以输入 . ~/.bash_profile

回答by Carl Norum

. ~/.bash_profile

Just make sure you don't have any dependencies on the current state in there.

只要确保你对那里的当前状态没有任何依赖。

回答by Mohammad Anini

Simply type:

只需键入:

. ~/.bash_profile

However, if you want to source it to run automatically when terminal starts instead of running it every time you open terminal, you might add . ~/.bash_profileto ~/.bashrcfile.

但是,如果您想让它在终端启动时自动运行而不是每次打开终端时都运行它,您可以添加. ~/.bash_profile~/.bashrc文件中。

Note:

笔记:

When you open a terminal, the terminal starts bash in (non-login) interactive mode, which means it will source ~/.bashrc.

当您打开终端时,终端会以(非登录)交互模式启动 bash,这意味着它将提供 .bashrc 文件~/.bashrc

~/.bash_profileis only sourced by bash when started in interactive login mode. That is typically only when you login at the console (Ctrl+Alt+F1..F6), or connecting via ssh.

~/.bash_profile仅在以交互登录模式启动时由 bash 提供。这通常是只有当你登录在控制台(Ctrl+ Alt+ F1... F6),或通过连接ssh

回答by hyper_st8

I like the fact that after you have just edited the file, all you need to do is type:

我喜欢这样一个事实,即在您刚刚编辑文件后,您需要做的就是输入:

. !$

This sources the file you had just edited in history. See What is bang dollar in bash.

这是您刚刚在历史记录中编辑的文件的来源。请参阅什么是 bash 中的 bang 美元

回答by hyper_st8

You can also use this command to reload the ~/.bash_profile for that user. Make sure to use the dash.

您还可以使用此命令为该用户重新加载 ~/.bash_profile。确保使用破折号。

su - username

回答by Mithun Khatri

  1. Save .bash_profilefile
  2. Goto user's home directory by typing cd
  3. Reload the profile with . .bash_profile
  1. 保存.bash_profile文件
  2. 通过键入转到用户的主目录 cd
  3. 重新加载配置文件 . .bash_profile

回答by Ulukai

If you don't mind losing the history of your current shell terminal you could also do

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

bash -l

bash -l

That would fork your shell and open up another child process of bash. The -lparameter tells bash to run as a login shell, this is required because .bash_profile will not run as a non-login shell, for more info about this read here

这将 fork 你的 shell 并打开另一个 bash 子进程。该-l参数告诉 bash 作为登录 shell 运行,这是必需的,因为 .bash_profile 不会作为非登录 shell 运行,有关此的更多信息,请阅读此处

If you want to completely replace the current shell you can also do:

如果要完全替换当前的 shell,还可以执行以下操作:

exec bash -l

exec bash -l

The above will not fork your current shell but replace it completely, so when you type exitit will completely terminate, rather than dropping you to the previous shell.

以上不会分叉您当前的 shell 而是完全替换它,因此当您键入exit它时,它将完全终止,而不是让您回到以前的 shell。

回答by Shemeer M Ali

Add alias bashs="source ~/.bash_profile"in to your bash file. So you can call bashsfrom next time

添加alias bashs="source ~/.bash_profile"到您的 bash 文件中。这样你bashs下次就可以打电话了

回答by Ezequiel De Simone

if the .bash_profile does not exist you can try run the following command:

如果 .bash_profile 不存在,您可以尝试运行以下命令:

. ~/.bashrc 

or

或者

 source ~/.bashrc

instead of .bash_profile. You can find more information about bashrc

而不是 .bash_profile。您可以找到有关bashrc 的更多信息

回答by Jenil Mewada

you just need to type . ~/.bash_profile

你只需要输入 . ~/.bash_profile

refer: https://superuser.com/questions/46139/what-does-source-do

参考:https: //superuser.com/questions/46139/what-does-source-do