On Sun, Sep 05, 2021 at 12:28:37AM -0500, Intense Red wrote: > > In /root/.bashrc I use this to give a red prompt including host and > > full path followed by a new line. > > I take this idea a bit further, setting a longer prompt and setting > workstation hosts for specific colors for user logins, and then doing a red > prompt for servers. > > Part of my ~/.bashrc: > > # Set the hostname to a specific color > HostName=`hostname -s` > if [ $HostName = "capncrunch" ]; then > HostColor="\[\033[1;36m\]" # Bright Cyan > elif [ $HostName = "piglet" ]; then > HostColor="\[\033[1;35m\]" # Bright Purple > elif [ $HostName = "wiseguy" ]; then
Not a big fan of case statements? HostName=${HOSTNAME%%.*} case $HostName in capncrunch) HostColor="\[\033[1;36m\]";; # Bright Cyan piglet) HostColor="\[\033[1;35m\]";; # Bright Purple ... esac Also, for the record, your quotes are in the wrong place in your [ commands. You need quotes around "$HostName" to avoid globbing and word splitting. You don't need quotes around simple strings like capncrunch and piglet, unless one of them contains whitespace or punctuation that's significant to the shell. The missing quotes around "$HostName" have never mattered because so far all of your hostnames have been safe. Maybe that's even a guarantee -- I'm not sure what characters are actually allowed in a Linux hostname. But quoting correctly still a good habit to get into.