For example, if I check $PS1 variable I get it:

[root@ENGDADOS ~]# echo $PS1
[\u@\h \W]\$

But if I reenter this exact variable, it changes from # (root) to $ (usually normal user)

[root@ENGDADOS ~]# export PS1="[\u@\h \W]\$ "
[root@ENGDADOS ~]$

How to reenter this envoriment variable without change from # to $? where is this configuration?


2 Answers 2


The $ character has special meaning inside double quotes, and other contexts, where it is used for parameter (variable) and command expansion. In these contexts, \ is used for escaping special characters, that is, interpreting them literally. For example:

$ a="1 2"
$ b="0 $a 3"
$ echo "$b"
0 1 2 3
$ b="0 \$a 3"
$ echo "$b"
0 $a 3

In order to include the literal string \$ at the end of PS1 you must either use single quotes to disable special shell constructs or escape both \ and $.

$ PS1='[\u@\h \W]\$'
$ PS1="[\u@\h \W]\\\$"

If you're using Bash I'd suggest using declare -p to inspect a variable, as it could also include trailing whitespace which you won't notice when using echo.

[root@hostname ~]# declare -p PS1
declare -- PS1="[\\u@\\h \\W]\\\$ "

In Bash PS1 is generally defined in the ~/.bashrc file.


Use single quotes.


root@d313d6954dee:/# echo '\u@\h:\w\$ '
root@d313d6954dee:/# echo "\u@\h:\w\$ "

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .