0

Between the various parameters that can be included in the bash PS1 variable, \w expands

the current working directory, with $HOME abbreviated with a tilde (uses the value of the PROMPT_DIRTRIM variable)

as stated in the Bash manual.

My $HOME is set to /home/myuser/ (the same value specified in /etc/passwd), but the expansion of \w in PS1 gives /home/myuser when I am in the $HOME directory. So, it is not «abbreviated with a tilde».

I am Using Ubuntu 16.04 with GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu).

What's wrong? What is the source from where \w actually copies the path of the current directory?

  • Do cd once to see if that helps. Also, is your home directory set to /home/myuser/, with a slash at the end, in /etc/passwd? – Kusalananda May 22 '17 at 21:27
  • @Kusalananda cd didn't have effect. As I wrote in the question, my home directory was /home/myuser/ with a slash in the end, also in /etc/passwd. – BowPark May 24 '17 at 14:53
4

The trailing / in /home/myuser/ is confusing bash. I think you'll see normal behavior if you remove it.

That slash isn't part of the directory name; it's a path separator. It shouldn't be in /etc/passwd, and it shouldn't be in $HOME.

You can test that theory without touching a file using just:

HOME=/home/myuser

after which the tilde should appear in your prompt.

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.