File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Mac OS and the fly likes Terminal prompt question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Mac OS
Bookmark "Terminal prompt question" Watch "Terminal prompt question" New topic

Terminal prompt question

marc weber

Joined: Aug 31, 2004
Posts: 11343

On my PowerBook, Terminal gives me a prompt like...

computerName:~ userName$

But on my iMac, Terminal gives me a prompt like...

user-xxlxxkx:~ userName$

...where the x's are digits. Does anyone know why it shows "user-xxlxxkx" instead of the computer name? Both machines are running bash, OS 10.4.6.

My reference book, The Mac OS X Command Line - Unix Under the Hood, just says that this part should be the computer name as shown on the Sharing panel under System Preferences. But my iMac's name is simply "imac-g5".
[ May 10, 2006: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
marc weber

Joined: Aug 31, 2004
Posts: 11343

Update: I've noticed that this only happens when my iMac is connected to the internet. When it's not connected, the correct name shows in the prompt.

It was suggested on the Apple boards that when I'm connected to my ISP's network, this might be the node name on that network rather than my computer's "given" name.

Does this make sense? I'm not network savvy, and I just want to make sure that something isn't misconfigured. (I connect differently with my PowerBook, so it makes sense that I would only see this on my iMac.)
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Yes, it makes sense if these two things are different.

The prompt is controlled by an idiosyncratic little code in the environment variable "PS1". The first component by default is "\h", which represents the host name. To learn how to customize the prompt, say "info bash", and then in the info program "/PS1" to find a link to the "Printing a Prompt" page, which explains all the codes.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Terminal prompt question
It's not a secret anymore!