Create a detached screen, send a command to it
<p>I'm trying to do something which is proving suprisingly difficult. I want to create a screen session <em>without</em> attaching to it (since this will eventually become a startup script), then send a bash command to the session.</p>

<p>I've tried to simply <code>echo Hello</code> in a newly created session. The screen session is created fine but the echo never happens. Given the following example, I would expect to finally attach to a screen which has "Hello" on it's console:</p>

<pre><code>screen -mdS "Test" # Create a screen session, do not attach to it
screen -ls # Confirm that the Test screen session exists
screen -S "Test" -X "echo Hello^M" # Send a command through
screen -R # Reconnect - notice the command didn't execute
</code></pre>

<p>But there's nothing in the session at all - the <code>echo</code> was not executed. Any pointers are hugely appreciated?!</p>