Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 script

screen -d -m -S $1                #start screen minimized
screen -S $1 -X stuff "$beast     
"                                 #stuff commands

unless I attach the screen first it seems the affects of stuff won't do anything? Why is this and how can I modify this script so I don't need to attach the screen?

share|improve this question

migrated from Oct 3 '11 at 11:52

This question came from our site for professional and enthusiast programmers.

up vote 14 down vote accepted

When you start a Screen session in detached mode (screen -d -m), no window is selected, so input later sent with screen -X stuff is just lost. You need to explicitly specify that you want to send the keystrokes to window 0 (-p 0). This is a good idea anyway, in case you happen to create other windows in that Screen session for whatever reason.

screen -S "$1" -p 0 -X stuff "$beast$(printf \\r)"

(printf \\r to strictly emulate the Return key; many but not all programs accept a newline (\n).)

share|improve this answer
Thanks! it works perfect. Sorry everyone for being off topic – Kevin Duke Jun 2 '11 at 8:56

This recently came up while trying to answer a question on

The summary is that screen does not have a default selected window unless you attatch, but Gilles showed us how you can force one to be selected by adding the argument -p 0 to your screen command.

Personally I recommend switching to tmux. Here is how you would port your screen commands to work in tmux:

tmux new-session -d -n $1
tmux send-keys -t $1 "$beast\n"
share|improve this answer

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.