How to execute a command in screen and detach

command linegnu-screenscript

How can I get screen to execute a command and then detach (That is, automatically in a single script without further input beyond initially starting the script)? e.g. I run and it automatically starts a screen session, executes a command, then detaches.

Best Answer

This is an easy one:

screen -d -m yourcommand

From the Screen User's Manual:

-d -m
Start screen in detached mode. This creates a new session but doesn’t attach to it. This is useful for system startup scripts.