user3164720
user3164720

Reputation: 71

export PS1 not working

I am setting the following in my users .profile file to display the last 3 directories in PWD but it's still only showing the home directory. Not sure what is wrong with this. Can anyone help, please?

me='$(whoami)'
function PWD {
pwd | rev| awk -F / '{print $1,$2,$3}'|rev|sed 's/ /\//g'
}
export PS1="$(whoami)@$(hostname -s)$PWD$ "

It keeps showing the user's home directory.

Upvotes: 2

Views: 5109

Answers (2)

Himansu
Himansu

Reputation: 328

In this link - http://ezprompt.net/, you can customize your PS1 variable easily. Then run the command generated i.e "export PS1=..."

Upvotes: 1

bishop
bishop

Reputation: 39474

Per the Bash Prompt How To, emphasis mine:

You can use the output of regular Linux commands directly in the prompt as well....

[21:58:33][giles@nikola:~]$ PS1="[\$(date +%H%M)][\u@\h:\w]\$ "
[2159][giles@nikola:~]$ ls
bin   mail
[2200][giles@nikola:~]$

It's important to notice the backslash before the dollar sign of the command substitution. Without it, the external command is executed exactly once: when the PS1 string is read into the environment. For this prompt, that would mean that it would display the same time no matter how long the prompt was used. The backslash protects the contents of $() from immediate shell interpretation, so date is called every time a prompt is generated.

Upvotes: 1

Related Questions