1

To keep track of which ssh connection I have open in different tabs I use the following ~/.bashrc script:

function set-title() {
  if [[ -z "$ORIG" ]]; then
    ORIG=$PS1
  fi
  TITLE="\[\e]2;$@\a\]"
  PS1=${ORIG}${TITLE}
}
set-title <SERVERNAME>;
echo "set-title <SERVERNAME>"

I do this for my tabs that I don't have ssh open (with set-title LOCAL;) and on two different servers. On one server it does exactly what I want to do and changes the tab name, but on the other server it does not change.

When I type set-title <SERVERNAME>; on the command line myself it does change the tab name, and when logging in it does echo "set-title <SERVERNAME>". Also, if I do source ~/.bashrc it works as expected, so it is only when logging in to the server that it does not work.

On the server where it works on login runs Scientific Linux release 6.7 (Carbon), on the server where it does not work runs CentOS release 6.6 (Final). What could cause the set-title <SERVERNAME>; in the .bashrc script to not run correctly on login?

2

Without further information, it’s not possible to answer this question.

However, I imagine the most likely scenario is that the .bashrc is sourced by on login by .bash_profile or .profile – probably something similar to this:

# source the users bashrc if it exists
if [ -f "${HOME}/.bashrc" ] ; then
  source "${HOME}/.bashrc"
fi

I’d guess that on the system where the title isn’t being set, the PS variable is being set to another value at a later stage in the logon script.

The PS1 variable should really be set in the Bash profile (.bash_profile or .profile) which is only run on login and the variable should be exporteded as an environment variable so that its value is inherited by any sub-shells.

PS1=${ORIG}${TITLE}
export PS1

or to use a short-hand that works for the Bash shell:

export PS1=${ORIG}${TITLE}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.