Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following bash script to set up a screen session with four windows from the command line in 13.10. Comments indicate what I think it ought to do.

screen -dmS mysession # start screen, name the session 'mysession'
screen -S mysession -p 0 -X exec echo -ne "\ekserver\e\\" # name the first window 'server'
screen -S mysession -p 0 -X exec screen # start a second window
screen -S mysession -p 1 -X exec echo -ne "\ekvim 1\e\\" # name second window 'vim 1'
screen -S mysession -p 1 -X exec screen # start a third window
screen -S mysession -p 2 -X exec echo -ne "\ekvim 2\e\\" # rename third window 'vim 2'
screen -S mysession -p 2 -X exec screen # start a fourth window
screen -S mysession -p 3 -X exec echo -ne "\ekconsole\e\\" # name fourth window 'console'

Every second or third time I run it, I get exactly what I want: four windows, each named as I have them here. The rest of the time I get anywhere between one and four windows, some of them named correctly, other times with the default, 'bash' name. Why am I seeing this behaviour, and how do I fix it?

Between each time I run it I make sure the screen session has ended, by typing exit in each window and checking screen -ls to see that there are no screen sessions active.

OUTCOME: From the comment by "chris" on this page I now have a project specific dotfile that I invoke from .screenrc using source .projectscreenrc - when the file is present it contains screen -t commands as suggested in glenn jackman's answer. When it is not present screen runs as normal. I'm still not sure why this works and why my original approach didn't, but this is much cleaner.

share|improve this question
My guess would be that screen -dm starts creating the session, then immediately returns, the next commands then sometimes get run before the session has been completely started/initialized. – geirha Jan 26 '14 at 12:03
up vote 3 down vote accepted

Not answering your question, but this is how I would use screen this way:

Put this in your ~/.screenrc:

screen -t server
screen -t vim_1
screen -t vim_2
screen -t console

Each time you want to enter screen, use screen -DR -- that will create the screen session if it does not exist, or reattach to it if it's running.

share|improve this answer
I don't know why the forums where screen window titling is discussed did not mention the -t option. – Fritz Meissner Jan 26 '14 at 11:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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