Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

How do I set the shell prompt in Mac OS X Terminal?

I'm new to Mac, last Apple I owned was a IIe in the 80's. This question is related to your book Learning Unix for Mac OS X Tiger book, page 41 "Changing the Command Prompt. In this section you give the following command for changing the prompt:

      PS1= "? "

I typed this, but got the following response from the terminal window:

      -bash: ? : command not found

What am I doing wrong?


Dave's Answer:

I can see exactly what the shell is complaining about, and I'll end any suspense by saying that you need to ensure that you never have superfluous spaces in the commands you type into Terminal or anywhere on a Unix command line. There's a world of different to the Bash shell between:

PS1= "? "

and

PS1="? "

Can you see where the extra space snuck in? Take it out, and you'll be sitting pretty with your prompt customization.

In general, this is a very common glitch for Linux and Mac command line users, one that can trip up even experienced users. If you're in doubt in the future, make sure that you eyeball the command you expect to have work and try removing any extra spaces, just to see if it'll work better.

My command prompt on my own Mac system, by the way, is:

PS1="\W \! $ "

Try it, you'll find it a pretty darn useful prompt, especially as you get more used to working with command history.

Also, it's important that you're in the correct shell when you're trying to set a command prompt because the C Shell and its family of command shells use a different notation. Try using the PS1="? " notation shown above and you're likely to get csh: PS1=? : Command not found. instead of a new prompt.

Csh uses a very different syntax for setting shell level variables, actually. To accomplish the same result in the C Shell, you'd use this:

set prompt="? "

Again, as with Bash, Csh also has lots of useful shortcuts too. In both cases, a check of the man page (use man bash for Bash, or man csh for Csh, for example) will reveal the many useful ways you can customize your prompt. Drop the customization into your .profile or .login, depending on your shell, and you'll be a happy command line user forever more!

Hope that helps you out!



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

Hi,
why doesn't it 'remember' the change the next time shell is run?
Thanks

Posted by: ablo at January 29, 2007 4:05 PM

hi sir,
I did'nt get the information what i required,My question is do we have command prompt in Mac OS alike in windows?

Please answer me
Thanks®ards
Ajay from india.

Posted by: Ajay at April 27, 2007 12:42 AM

Ajay, yes. Instead of START -> Run... you have Applications -> Utilities -> Terminal.app

Posted by: Dave Taylor at April 27, 2007 5:52 AM

Dave,

I'm a big fan of yours and hope to get out to the Colorado area soon; however, I've run into a problem with my lovely OS X terminal. I use it daily and love to use ssh within it, but now it seems that anytime I launch my terminal I find myself getting the following situation:

------------------------------------------

Last login: DOW MON ## HH:MM:SS on ttyp1
ssh 192.168.0.70
Welcome to Darwin!
Mac-Pro:~ steven$ ssh 192.168.0.70
steven@192.168.0.70's password: _

------------------------------------------

I can't figure out for the life of me where it is automatically retrieving the ssh 192.168.0.70 command. I've used this command before via QuickSilver and wonder if this may be the cause but I can't identify where to get rid of within there. I've tried everything I can think of for several hours now and would _really_ love to not have to hit CTL+C everytime I load up my terminal window.

Any help is greatly appreciated!!!

Thanks,

Steven

Posted by: Steven at June 11, 2007 8:59 PM

Steven, look in your ~/.profile or ~/.bashrc (if you're running bash). I'd do this, actually:

$ cd
$ find .[a-zA-Z]* | xargs grep -i 192

and see if it pinpoints that command anywhere. Good luck!

Posted by: Dave Taylor at June 13, 2007 12:46 AM

it would be nice if you could show what the symbols mean. Personally, I like to see the whole directory branch otherwise it is easy to get lost. How would a person do that?

Posted by: chris at September 3, 2007 8:41 PM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]