Comment 9 for bug 1276796

Revision history for this message
Rodney Beede (business2008+launchpad) wrote : Re: bash fails to provide FQDN for PS1 with \H

I've submitted a bug report up-stream. A copy of that bug report is attached.

To: <email address hidden>,<email address hidden>
Subject: bash fails to provide FQDN for PS1 with \H

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I../bash -I../bash/include -I../bash/lib -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall
uname output: Linux okdev1383 3.11.0-15-generic #23-Ubuntu SMP Mon Dec 9 18:17:04 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.2
Patch Level: 45
Release Status: release

Description:
        The bash man page offers two options for the PS1 prompt: \h and \H. \h is suppose to be for the short form of the host name whereas \H can be the longer form. The text reads:

\h
The hostname, up to the first ‘.’.

\H
The hostname.

The difference would imply that using \H would give you the FQDN version of the host name, but that is not the case. It is distro specific.

See https://bugs.launchpad.net/ubuntu/+source/bash/+bug/1276796 for a discussion thread on this issue in Ubuntu.

Repeat-By:
        Tested on Ubuntu 12.04 and 13.10. Set PS1 with \H. Because Ubuntu's installer creates /etc/hostname without the FQDN (as recommended in their man pages) bash never gets a host name other than the short version.

Fix:
        Option 1: use a function other than gethostname when the \H option is supplied. If the system doesn't have a FQDN this may not change anything, but it has a better chance at avoiding disto specific behavior.

        Option 2: Update the documentation as follows:

\h
The hostname, up to the first '.'.

\H
The hostname. May or may not include the domain name or FQDN.