You can put your commands in a file, e.g., myscreenrc
, like this:
screen command1
screen command2
screen command3
and then execute screen
with the -c
option followed by the name of that file, e.g.,
screen -c myscreenrc
UPDATE
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.
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 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:
. ~/.bashrc
top
Then put this line in the file we're calling screenrc
:
screen bash --rcfile ~/runtop -i
and start screen
as
screen -c screenrc
Best Answer
Yes you can using the backtick feature. Backtick
You put a line in your screenrc file:
If I understand correctly, it means backtick id 1, which runs command
/bin/date
, produces output valid for 0 seconds and the caption/hardstatus should be updated every 5 seconds.Now, you can use the string
%1`
inside your hardstatus for substitution, egIn your case, I think you'll have to write a script. For example,
$HOME/my_script.sh
:In your
~/.screenrc
:Obviously you won't want exactly that, but just add
%1`
to whatever else you have. Note that your script output can't include string escapes for screen to expand, e.g. if your script isecho "%{bg}blue on green%{dd}"
it won't be coloured, you'll just see${bg}
and${dd}
in your status line.