i'd like to launch GNU screen, some shell command in it, then open new screen window(s) with different command(s) – all that automatically, from a script. is it possible?
UPDATE
the screen windows should not be closed after executing the commands, i just want to have the screen session preserved (and detached)
Best Answer
You can put your commands in a file, e.g.,
myscreenrc
, like this:and then execute
screen
with the-c
option followed by the name of that file, e.g.,UPDATE
in reponse to the updated question. The commands I used for testing were
screen vim foo
andscreen vim bar
, so I didn't see the screen-closing problem. The following solves the screen-closing problem, but it seems a bit of a kludge.ls
was just a convenient command for testing this problem.UPDATE #2
Another approach would be to start the command from the shell's rc file rather than from screen's rc file. It requires another file for each command, though. For example, to run
top
in ascreen
window such that quittingtop
will return you to abash
prompt in that same window, create a file, call itruntop
, that contains the following:Then put this line in the file we're calling
screenrc
:and start
screen
as