How to make the PS1 string always be reevaluated each time the user inputs the enter key at the shell prompt?

actual in mine:

n=A; PS1="$n"


The prompt keeps showing A. How to solve it?

1 Answer 1


Your $PS1 variable is using $n once because $n is evaluated and replaced with its value when $PS1 is initially set. This is because you are using double quotes, in bash, it evaluates the variables in the double-quoted string in an assignment.

If you want your $PS1 to reflect the current value of $n, you need to either have single quotes around the $n or escape the dollar sign.

For example:




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.