[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug] Home dir in PS1 not abbreviated to tilde

From: dethrophes
Subject: Re: [bug] Home dir in PS1 not abbreviated to tilde
Date: Tue, 13 Mar 2012 16:28:30 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

Am 13.03.2012 16:18, schrieb Roman Rakus:
On 03/13/2012 04:08 PM, dethrophes wrote:
Am 13.03.2012 06:04, schrieb Clark J. Wang:
On Mon, Mar 12, 2012 at 12:22, Yongzhi Pan<address@hidden> wrote:

Tested in GNU bash, version 3.00.16(1)-release and 4.1.2(1)-release.

Upon login, home dir is displayed as tilde in PS1:
address@hidden ~$ echo $PS1
address@hidden \w$ \[\033[0m\]
address@hidden ~$ pwd

After a cd command, which change directory to $HOME (not changed at all),
it is displayed as the complete path:
address@hidden ~$ cd
address@hidden /export/home/pan$

The reason is that my home in passwd has a trailing slash:
address@hidden /export/home/pan$ grep ^$USER: /etc/passwd

You can also reproduce this by directly setting HOME to

This is tricky to find. I hope it will display tilde even if home dir entry
in passwd has one or more trailing slash.

I personally don't think this needs to be fixed. :)
I agree, or to be more acurate I think you should fix the passwd entry.
PS: I read the source code and do not know where this is done, maybe in

as a workaround to your problem you could have something like this in your bashrc
if shopt extglob &>/dev/null ; then
  HOME="${HOME/%+(\/)}"   # strip all trailing forward slashes
   while [ "${HOME}" != "${HOME%\/}" ] ; do

I think it should hide your problem.

Is it all necessary?

not really just being thorough.
the request was remove/handle all/multiple trailing forward slashes. e.g. /home/jjjj////////////////////
HOME="${HOME%\/}"  # only removes 1

HOME="${HOME%%+(\/)}" # removes all but only if extglob supported and enabled

the while loop was a fallback in case extglob is either not enabled or not present.

so it depends on your needs I would suggest that
 should cover most real world cases
or this on its own isn't pretty but does the job
while [ "${HOME}" != "${HOME%\/}" ] ; do

reply via email to

[Prev in Thread] Current Thread [Next in Thread]