How do you start Unix screen command with a command?

Ethan picture Ethan · Feb 12, 2009 · Viewed 44k times · Source

According to the docs for the Unix "screen" command, you can configure it in .screenrc to start with a bunch of default screens, each running a command that you specify.

Here's my cofig:

# Default screens
screen -t "shell_0"  1
screen -t "autotest" 2 cd ~/project/contactdb ; autotest

It will not run the autotest command. That window where I'm trying to run autotest just closes instantly when I start screen.

I also tried it with just...

screen -t "autotest" 2 cd ~/project/contactdb

Same result.

I also tried...

screen -t "autotest" 2 ls

Same result there too.

What's the secret to getting it to run a command in a given screen on startup?

Answer

chaos picture chaos · Feb 12, 2009

Your program is being run (well, except the cd), it's just that it's being run without a parent shell, so as soon as it completes, it exits and you're done.

You could do:

screen -t "autotest" 2 bash -c 'cd ~/project/contactdb ; autotest'

Spawns two shells, but life will probably go on.