bash 如何更改以在 .bashrc 文件中永久提示在 osx 上?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14607617/
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-18 04:23:40  来源:igfitidea点击:

How do I make changes to prompt in .bashrc file permanent on osx?

macosbashterminalprompt

提问by dwstein

I'm a n00b trying to permanently change my terminal prompt.

我是一个试图永久更改我的终端提示的 n00b。

I've used the following tutorials/threads:

我使用了以下教程/线程:

http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html

http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html

http://www.linuxquestions.org/questions/programming-9/how-to-edit-bash_profile-and-bashrc-files-678445/

http://www.linuxquestions.org/questions/programming-9/how-to-edit-bash_profile-and-bashrc-files-678445/

I've managed to change the .bashrc file:

我设法更改了 .bashrc 文件:

$ cat .bashrc
export PS1="\w $"

but the prompt is still not coming up the way I want it.

但是提示仍然没有按照我想要的方式出现。

On temporary basis the following works:

暂时进行以下工作:

$ PS1="\w $"
~ $

Am I editing the wrong file?

我是否编辑了错误的文件?

采纳答案by fedorqui 'SO stop harming'

Two suggestions:

两个建议:

  • After changing the .bashrcfile, unlog and log again to see if it works.
  • Put it also in .profile, as .bashrcis only used if you have /bin/bashas your default shell.
  • 更改.bashrc文件后,取消登录并再次登录以查看是否有效。
  • 也将它放在 中.profile,因为.bashrc只有在您将其/bin/bash作为默认 shell时才使用。

回答by James

I am only answering this here because I just searched for the solution to this problem today and this thread popped up near the top. I figured i'd give an ultimate noob guide for "how to" get this done on Mac, as i like things written out very detailed =P

我只是在这里回答这个问题,因为我今天刚刚搜索了这个问题的解决方案,这个线程在顶部附近弹出。我想我会给出一个关于“如何”在 Mac 上完成这项工作的终极菜鸟指南,因为我喜欢写得很详细的东西 =P



您需要添加.bash_profile.bash_profile一个隐藏文件。之所以要更改此文件,是因为这是每次启动 bash shell 时都会加载的文件。但在执行此操作之前,请确保您已告诉 bash 您希望显示隐藏文件(you how to hide them after你如何在之后隐藏它们):

Copy/Paste into Terminal:

复制/粘贴到终端:

defaults write com.apple.finder AppleShowAllFiles TRUE

followed on a new line by:

紧接着换了一行:

killall Finder

After making all files visible, you must then navigate into the main user-directory located at HD > Users > YourUserName. Once you're inside, locating the .bash_profilefile should be relatively easy. Drag the bash file over to your preferred text editor. This is where you will add the commmand (or your own custom variation):

使所有文件可见后,您必须导航到位于HD > Users > YourUserName. 进入内部后,定位.bash_profile文件应该相对容易。将 bash 文件拖到您喜欢的文本编辑器中。 您将在此处添加命令(或您自己的自定义变体):

export PS1="\w $"

Once you are satisfied with your changes, you need to save and restart bash in order for them to take effect. In order to hide files that were made visible earlier, copy/paste the follow two lines subsequently into your terminal:

一旦您对更改感到满意,您需要保存并重新启动 bash 以使它们生效。为了隐藏之前可见的文件,请将以下两行复制/粘贴到您的终端中:

defaults write com.apple.finder AppleShowAllFiles FALSE

killall Finder