#859384 bash: bogus home dir handling in PS1 \w\W and cd

Package:
bash
Source:
bash
Description:
GNU Bourne Again SHell
Submitter:
Paul Wise
Date:
2024-08-08 14:18:05 UTC
Severity:
normal
#859384#5
Date:
2017-04-03 01:54:06 UTC
From:
To:
The HOME environment variable does not have to be present, programs
must fall back to the value in the passwd file. bash does not do this
in the following two places. The documentation for both of these says
that the HOME shell variable is used but bash should still change that,
especially because the tilde expansion feature of bash already does.

When running cd without any argument:

POSIX leaves cd with $HOME unset as implementation defined:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cd.html

When expanding \w or \W in PS1:

PS1 \w \W seem to be bash-specific features:

http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_05_03

pabs@chianamo:~$ export PS1='\u@\h \w \W \$ '
pabs@chianamo ~ ~ $ echo $PS1
\u@\h \w \W \$
pabs@chianamo ~ ~ $ unset HOME
pabs@chianamo /home/pabs pabs $ cd
-su: cd: HOME not set
pabs@chianamo /home/pabs pabs $ echo ~
/home/pabs
pabs@chianamo /home/pabs pabs $ getent passwd pabs | cut -d: -f6
/home/pabs

#859384#10
Date:
2017-04-25 02:42:06 UTC
From:
To:
Nope, there's nothing that says they "must" fall back to anything.  The very
docs you linked to:
explicitly say the results are unspecified.  $HOME should be set by the
login environment, but if it's not set, you get to keep the pieces.

You filed copies of this bug on three shells: busybox[sh], dash, bash.
Their policies are:
* busybox: no superfluous features are added, often even required but
  non-important features get skipped
* dash: POSIXLY_CORRECT, even when POSIX and common sense disagree
Upstreams of those two will thus almost certainly reject such a change.
* bash: no particular policy
Yet, because the two other shells don't invent a fallback for missing $HOME,
adding it bash would introduce a difference in behaviour that can be avoided
by keeping status quo.

Thus, while I understand your reason (extra robustness for user error), I'd
recommend WONTFIXing all three copies of this bug.


Please say if I missed something.