How to use custom hostname in shell prompt
Typically, the Linux shell prompt looks like this
how-to-use-custom-hostname-in-shell-prompt.sh
user@hostname$If you want to use a custom string instead of hostname, edit /etc/bash.bashrc: and find the following line:
bashrc_ps1_line.sh
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ 'Now, replace \h (i.e. hostname) with your custom string. For example, if you want to use mycustomhostname instead of the actual hostname, the line should look like this:
bashrc_custom_ps1_line.sh
PS1='${debian_chroot:+($debian_chroot)}\u@mycustomhostname:\w\$ 'This might still not override it for individual users. If that’s the case, you can edit the PS1= line in ~/.bashrc:
bashrc_user_ps1_line.sh
PS1='${debian_chroot:+($debian_chroot)}\u@mycustomhostname:\w\$ 'Typically, in ~/.bashrc, there are two different PS1= lines, one for colored output and one for non-colored output.
Replace \h in both of them.
bashrc_ps1_block.sh
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fiWhen replaced with mycustomhostname, it should look like this:
bashrc_custom_ps1_block.sh
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@mycustomhostname\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@mycustomhostname:\w\$ '
fiCheck out similar posts by category:
Linux
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow