Starting up a screen (unix command) + running a command in 1 command?

command-line, gnu-screen, unix

Solution

screen -d -m sh -c "while :; do ./myCommand; done;"

Explanation:

- `-d -m` starts screen in detached mode (create session but don't attach to it)

- `sh -c commandline` starts a shell which executes the given command line (necessary, since you are using the `while` builtin).

Problem

Was wondering how I can start up a command such as: ``` while :; do ./myCommand; done; ``` But instead of doing the usual ``` screen -S nameOfMyScreen ``` Then the command ``` while :; do ./myCommand; done; ``` Then detach the screen ``` ^a ^d (Control "a" the control "d" ``` I would like it to start and detach. Thanks!

Original source