Run a program with GNU screen and immediately detach after

Did you really mean to put the \ at the end of the line? If not then try removing those - they escape the following character.

also, dropping the -X helps the setup work for me, for instance:

screen -S test -d -m -X touch /tmp/test

fails with No screen session found, however:

screen -S test -d -m touch /tmp/test

works fine. As such I suspect the following will work for you:

#!/bin/bash
screen -S test -d -m $HOME/folder/folder/.program
screen -S test2 -d -m $HOME/folder/folder/.program2

Remember, that if you run this at boot time, $HOME is not the same as after you log in as a specific user. If you need to run it as a certain user you'll need to use the likes of su to run it as that user, and specifying the full path will remove any ambiguity:

#!/bin/bash
screen -S test -d -m su - username /home/username/folder/folder/.program
screen -S test2 -d -m su - username /home/username/folder/folder/.program2

Or, you would call the entire script above as su - username /path/to/your/script.


Like Cry Havok mentioned, you can place the program right on the command-line.

If you really must use the -X option, then a) you need to specify the 'screen' command and b) the session needs to exist beforehand.

screen -dmS test
screen -S test -X screen $HOME/folder/folder/.program
screen -dmS test2
screen -S test2 -X screen $HOME/folder/folder/.program2