To change the color of the shell prompt in Bash, you can use the PS1
variable. This variable contains the value of the prompt that is displayed by the shell, and you can modify it to change the appearance of the prompt.
For example, to change the color of the prompt to red, you can use the following command:
$ PS1="\[\e[0;31m\]\u@\h:\w\$ \[\e[m\]"
This will set the PS1
variable to a string that specifies the prompt text and color. The \[\e[0;31m\]
part of the string specifies that the prompt text should be red, and the \[\e[m\]
part of the string specifies that the prompt should return to the default color after the prompt is displayed.
Note that this change will only affect the current Bash session. If you want to make the change permanent, you will need to add the PS1
assignment to your ~/.bashrc
file. This will ensure that the prompt is set to the desired color every time you start a new Bash session.
Overall, changing the color of the shell prompt in Bash is a simple and effective way to customize the appearance of the prompt. By using the PS1
variable, you can easily modify the prompt to suit your preferences and needs.