Search code examples
bashtitlegnu-screenxterm

Set screen-title from shellscript


Is it possible to set the Screen Title using a shell script?

I thought about something like sending the key commands ctrl+A shift-A Name enter

I searched for about an hour on how to emulate keystrokes in an shell script, but didn't find the answer.


Solution

  • You can set the screen / xterm title using the following lines:

    #!/bin/bash
    
    mytitle="Some title"
    echo -e '\033k'$mytitle'\033\\'
    

    [UPDATE] - by request I'm also including the solution proposed by @Espo below:

    Depending on your xterm version or your linux distribution the line above may or may not work and you can try the xterm-defaults:

    #!/bin/bash
    
    mytitle="Some title"
    echo -e '\033]2;'$mytitle'\007'
    

    For more on the details see: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#s3 or refer to the answer by @Espo below.