Chapter 4. Interacting with Your Environment
Basics of Setting the Prompt
The prompt displayed by your shell is contained in a shell variable (Section 35.9) called prompt in C-type shells and PS1 in Bourne-type shells. As such, it can be set like any other shell variable.
There are two or three ways to set a prompt. One is a static prompt (Section 4.2) that doesn’t change during your login session (as you change directories, as the time of day changes, etc.). Some shells let you set a dynamic prompt (Section 4.3) string that is interpreted by the shell before each prompt is printed. Even on shells that don’t interpret prompt strings dynamically, you can simulate a dynamic prompt (Section 4.4) by changing the prompt string automatically.[1]
Depending on your shell’s capabilties, you can use or combine those three techniques — and those found in the rest of this chapter — to do a lot. But, of course, you don’t want to type that prompt-setting command every time you log in. So after you’ve perfected your prompt on the command line, store it in the correct shell setup file (Section 3.3): use the file that’s read by interactive shells or add an interactive shell test to your setup file. (Setting the prompt in noninteractive shells is pointless — and it can even cause problems (Section 4.5).)
—JP, TOR, and SJC
Static Prompts
As Section 4.1 explains, the simplest prompts — which I call static prompts — are prompts whose value are set once. The prompt doesn’t change (until you reset the prompt ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access