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?
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= "? "
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!