How to change the terminal prompt to just current directory? [closed]

拟墨画扇 提交于 2019-12-22 03:23:05

问题


I am using a Macbook Pro, and I wanted to change it to the current directory and a dollar sign prompt in Terminal. I've already looked at these resources to try and solve this issue.

I tried modifying the ~/.bashrc file and saving it but it did not seem to work.

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting

### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
export PS1="\W$ ”

The last line is what I added to change the prompt.


回答1:


This should be done in .bash_profile, not .bashrc.

nano ~/.bash_profile

Add a line containing this:

export PS1="\W\$ "

.bashrc is ONLY excuted when starting a sub-shell. bash login shell uses the following initialization scripts:

.bash_profile
.bash_login
.profile



回答2:


You need to escape the dollar sign. Like this:

$ PS1="\W\$ "
~$ cd tmp
/Users/philip/tmp
tmp$

And once you change your .bashrc you either need to logout/back-in or . ~/.bashrc to re source it.

I would humbly recommend not doing this. Having a full path is very useful as 'tmp' directories could be anywhere. Consider using "\w" which does relative path (ie. uses ~ to represent HOME)



来源:https://stackoverflow.com/questions/20913134/how-to-change-the-terminal-prompt-to-just-current-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!