Take the 2-minute tour ×

I have a script and use the following command in it:

screen -dmS name bash -c "ls -1 > out"

What I am trying to achieve is to create a screen session, run a command and detach from it. The command above is working fine, except for the screen session which is being terminated:

screen -list

Why the session is not saved despite on the -dm parameters?

share|improve this question
What would you expect the (detached) screen to contain, given that the command you feed it runs once, and then exists? To compare, trying doing the same but by starting something interactive, like a text editor. –  andol Jan 8 '12 at 17:50
You're right. It's working with interactive commands like 'vi'. Is there any possibility to keep the screen session detached while running a non-interactive command? –  Andrew Jan 8 '12 at 18:14
May I ask what you are trying to accomplish? What use would you have of being able to reattach a screen where that command had been run? –  andol Jan 8 '12 at 18:21
Add "zombie cr" to your .screenrc file - it'll keep windows around when the child process has exited unless you press "r" or "c". –  Steve Kemp Jan 8 '12 at 18:36
Yes, 'zombie cr' helped. Please post it as a reply and I will accept it as a solution. –  Andrew Jan 8 '12 at 19:07

1 Answer 1

up vote 1 down vote accepted

Add to your ~/.screenrc file :

 zombie cr

That setting will keep any internal screen windows open when the child process has exited.

You then press "c" or "r" to clear or resurrect the screen. You can see further details on the zombie setting if you run "man screen"

share|improve this answer

Your Answer


