Bash Prompt: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
* https://unix.stackexchange.com/questions/100959/how-can-i-change-my-bash-prompt-to-show-my-working-directory
* https://linuxconfig.org/bash-prompt-basics
=Internal=
=Internal=
* [[bash#Subjects|bash]]
* [[bash#Subjects|bash]]
Line 5: Line 9:
=Overview=
=Overview=


Set PS1 environment variable in .bashrc.
Set PS1 environment variable in .bashrc. PS1 is a primary prompt variable. PS2 bash shell variable is a secondary prompt. This prompt is displayed if the shell waits for a user input.
 
If used in PS1 definition, the following control character are rendered to various pieces of information:
* \w working directory
* \u username
* \H host name
* \h host name up to the first "."
 
=Re-evaluate the Prompt on Directory Change=
 
Introduce the command to be executed with backslash dollar instead of simply dollar:
 
Incorrect:
<syntaxhighlight lang='bash'>
export PS1="$(some-prompt-generating-function)"
</syntaxhighlight>
 
Correct:
<syntaxhighlight lang='bash'>
export PS1="\$(some-prompt-generating-function)"
</syntaxhighlight>

Latest revision as of 03:41, 16 July 2020

External

Internal

Overview

Set PS1 environment variable in .bashrc. PS1 is a primary prompt variable. PS2 bash shell variable is a secondary prompt. This prompt is displayed if the shell waits for a user input.

If used in PS1 definition, the following control character are rendered to various pieces of information:

  • \w working directory
  • \u username
  • \H host name
  • \h host name up to the first "."

Re-evaluate the Prompt on Directory Change

Introduce the command to be executed with backslash dollar instead of simply dollar:

Incorrect:

export PS1="$(some-prompt-generating-function)"

Correct:

export PS1="\$(some-prompt-generating-function)"