bug-bash
[Top][All Lists]
Advanced

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

Re: PS-embedded comsub `\w' evaluation doesn't replace $HOME with ~


From: Rob Foehl
Subject: Re: PS-embedded comsub `\w' evaluation doesn't replace $HOME with ~
Date: Sun, 12 Mar 2017 17:17:56 -0400 (EDT)
User-agent: Alpine 2.20 (LFD 67 2015-01-07)

On Sun, 12 Mar 2017, Grisha Levit wrote:

For example:

$ PS1='\w $(echo \w) $ '
~ /home/levit $

This seems to work as documented, for the same reason this happens:

╶➤ echo ~
/home/rob

The expansion order is perhaps non-obvious: the prompt string backslash escapes are replaced before the string is subject to any other expansions.

Obviously, this is easy enough to work around in most cases by
replacing \w with ${PWD/#$HOME/~}.  I had a silly application for
calculating prompt length and this was throwing it off, but this
behavior has been there since at least 2.05b so not sure if it's worth
changing..

Doing anything that depends on calculating (any part of) the prompt length at expansion time in PS1 is... complicated.

╶➤ echo ${#PS1}
1485

I have on occasion wondered how difficult it'd be to make ${#...} applicable to any arbitrary expansion, but I also can't think of another use case...

-Rob

reply via email to

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