Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I can print my current working dir like this

myPrompt$ pwd
/Users/me/myDir

I want my shell to look like this

/Users/me/myDir$ pwd
/Users/me/myDir

Is that possible? How can I do it?

share|improve this question
    
On OS X the name of the file is .bash_profile not just .profile. That will autoload for you. –  user81596 Aug 21 at 21:54
    
Not quite. OSX starts login shells by default and that means that bash looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. In any case, this is really a comment and not an answer so I am converting it to one. –  terdon Aug 21 at 22:03

1 Answer 1

You can use escape sequences in prompt variables.

Put this in your ~/.bashrc:

PS1='\w\$ '
share|improve this answer
    
thanks. I made that change. Now I see: Abrams-MacBook-Air-3:tmp abramhandler$ pwd; /Users/abramhandler/tmp Abrams-MacBook-Air-3:tmp abramhandler$ .... I want to only show the part that says "tmp" for my prompt. How do I hide the rest? I want to hide the "abramhandler" and "Abram's-MacBook-Air-3" parts –  akh2103 Nov 13 '13 at 1:00
2  
@akh2103 use \W instead of \w. See the link Gilles gave you for a (short) explanation of the escape codes. –  terdon Nov 13 '13 at 1:00
    
@terdon I see the same thing with \W and \w. I am running Unix on OSX. –  akh2103 Nov 13 '13 at 1:03
1  
@akh2103 if you are running OSX and using the terminal app, you should make changes to ~/.profile not .bashrc since terminal runs a login shell by default. You should also source ~/.profile or open a new terminal for the changes to take effect. Also, please edit to add more information, I can't understand what you are asking for from your last comment. –  terdon Nov 13 '13 at 1:11
    
@terdon when I run source ~/.profile it changes the path properly in the current terminal. But when I open a new terminal then I still see "abram's mac book air" etc. I tried adding source ~/.profile to both the .profile and .bashrc files but still no luck. Any ideas? –  akh2103 Nov 13 '13 at 1:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.