Variables in Prompt
Using the following variables, you can display information about the current state of the shell or the system in your bash prompt. Set the PS1
variable to a string including the desired variables. For instance, the following command sets PS1
to a string that includes the \w
variable to display the current working directory and the \!
variable to display the number of the current command. The next line is the prompt displayed by the change.
$ PS1='\w: Command \!$ '
~/book/linux: Command 504$
Variable |
Meaning |
|
Alarm (bell). |
|
Date in the format “Mon May 8”. |
|
Escape character (terminal escape, not backslash). |
|
Hostname. |
|
Number of background jobs (active or stopped). |
|
Current terminal name. |
|
Newline inserted in the prompt. |
|
Carriage return inserted in the prompt. |
|
Current shell. |
|
Time in 24-hour format, where 3:30 p.m. appears as 15:30:00. |
|
User’s account name. |
|
Version and release of bash. |
|
Current working directory. |
|
Time in 24-hour format, where 3:30 p.m. appears as 15:30. |
|
Time in the specified format interpreted by strftime; an empty format displays the locale-specific current time. |
|
Like \h. |
|
Time in 12-hour format, where 3:30 p.m. appears as 03:30:00. |
|
Version, release, and patch level of bash. |
|
Last element (following last slash) of current working directory. |
|
Single backslash inserted in the ... |
Get Mac OS X Tiger in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.