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.,
screen -c myscreenrc
in reponse to the updated question. The commands I used for testing were
screen vim foo and
screen 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.
screen bash -c 'ls foo; exec bash -i'
screen bash -c 'ls bar; exec bash -i'
ls was just a convenient command for testing this problem.
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 a
screen window such that quitting
top will return you to a
bash prompt in that same window, create a file, call it
runtop, that contains the following:
Then put this line in the file we're calling
screen bash --rcfile ~/runtop -i
screen -c screenrc