G
G
ge2021-01-26 09:16:15
bash
ge, 2021-01-26 09:16:15

Why isn't $HOME replaced with a tilde in bash prompt?

The essence of the problem is that the substitution of tilde instead of $HOME does not work correctly in prompt. It is reproduced like this: - You open the terminal (no matter which one), everything is fine. - After changing to any folder or doing cd , the absolute path is already displayed instead of the tilde. Visually (my prompt is two-line):

PS1="> \[\033[0;92m\]\w\[\033[0;15m\]\n\$ "




> ~
$ cd
> /home/gd
$


My bash version is 5.1.4(1)-release.

I have already smoked out the mana, there is nothing in the bash except \w for automatic substitution of the tilde instead of $HOME. There is a \W (and it works) that shows the current directory (basename), but I don't need it like that.

I tried to solve the problem with my hands like this:

${PWD//${HOME::(-1)}/\~}

But it also does not work in prompt. If output via echo , then ok. Both this code and the PS1 itself work fine in Ubuntu.
btw i use arch.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2021-01-26
@gedev

Here is an ancient thread https://lists.gnu.org/archive/html/bug-bash/2012-0... with a similar error due to an extra slash at the end of $HOME.
Check that you have HOME in /etc/passwd

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question