Search code examples
bash

Bash PS1 prompt setting \h strips the hostname after the first dot


My system hostname is like this: 192.168.2.1_machine05 and my bash prompt $PS1 setting is [\u@\h \W]\$.

Since there is a dot character in the hostname, the \h variable extracts only the first portion of the string that comes before the first dot character and rest of the characters that follows the first dot are ignored.

To avoid it I have to use: PS1='[\u@$(uname -n) \W]\$ '

Can I make this \h variable show the complete hostname?


Solution

  • According to bash manual (in section PROMPTING):

    \h     the hostname up to the first '.'
    \H     the hostname