PDA

View Full Version : alias hostname on console



Lee_Machine
April 6th, 2013, 06:58 AM
So I'm changing hostnames on my servers but I would like to have the old hostname be displayed at the BASH prompt, ie username@hostname. I've tried defining this in both the local bashrc file as well as the gobal. The same goes for the local and global bash_profile files. Any ideas?

Something like this seems to be on the right track, but I cannot get the syntax to work.




HOST= hostname
PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOST%%*}" "${PWD}"'


Thanks for the help.

r-senior
April 6th, 2013, 08:46 AM
I'm going to assume Bash shell.

Did you try using PS1?

~/.bashrc


...

export HOST="oldhostname"
export PS1="\u@$HOST:\w$ "

You can also include non-printing characters in PS1; refer to the section entitled PROMPTING in the Bash manual page.

ofnuts
April 6th, 2013, 10:48 AM
If you just want it displayed; hardcode it in PS1:


PS1="\u@old.host.name:\w$ "

Lee_Machine
April 6th, 2013, 02:36 PM
I'm going to assume Bash shell.

Did you try using PS1?

~/.bashrc


...

export HOST="oldhostname"
export PS1="\u@$HOST:\w$ "

You can also include non-printing characters in PS1; refer to the section entitled PROMPTING in the Bash manual page.


Thank you! That worked :)