简体   繁体   中英

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

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

I've used the following tutorials/threads:

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/

I've managed to change the .bashrc file:

$ 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?

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


You need to make an addition to .bash_profile which is a hidden file. The reason why you change this file is because this is the one that is loaded every time you start up the bash shell. But before doing this make sure you have told bash that you want hidden files to be displayed ( you how to hide them after ):

Copy/Paste into Terminal:

export PS1="\w $"

followed on a new line by:

defaults write com.apple.finder AppleShowAllFiles FALSE

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_profile file 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 ):

 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:

 defaults write com.apple.finder AppleShowAllFiles FALSE killall Finder 

Two suggestions:

  • After changing the .bashrc file, unlog and log again to see if it works.
  • Put it also in .profile , as .bashrc is only used if you have /bin/bash as your default shell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM