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" n=B
The prompt keeps showing A. How to solve it?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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.