[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: Chet Ramey
Subject: Re: [bug] Home dir in PS1 not abbreviated to tilde
Date: Tue, 13 Mar 2012 08:58:40 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

On 3/12/12 12:22 AM, Yongzhi Pan 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
> /export/home/pan/
> 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$

Strictly speaking, the tilde prefix only extends up to the first slash.
Pathname canonicalization cuts off the final slash of the directory
name, so the directory target of `cd' (and therefore $PWD) won't match
$HOME, and you won't get the abbreviation.  I'm surprised it matches the
first time, but the pathname you get from the environment probably hasn't
been canonicalized.

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

This isn't a good idea in any case.


``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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