Optimus Prime
Optimus Prime

Reputation: 36

Setting ${PWD} in PS1 variable does not work in Korn Shell

I have set the below as my PS1 variable in Solaris 5.10

PS1="\[${USER}@`uname -n` ${PWD}]\$ "

When I start my terminal session, it shows the correct directory(i.e my home directory) but when I change to some other directory it actually does not work. It still keeps on showing my home directory.

Any idea why this happens and how to rectify this ?

Upvotes: 1

Views: 3307

Answers (1)

NeronLeVelu
NeronLeVelu

Reputation: 10039

Variables contained in strings enclosed in " get evaluated on the first encounter.

$PS1 also gets evaluated every time before it's displayed.

You need to escape the $ to postpone the evaluation of $PWD:

PS1="\[\${USER}@`uname -n` \${PWD}]\$ "

Upvotes: 5

Related Questions