GNU screen
takes a number of options, and then an optional command to start within the screen session. If no command is given, the screen
session will contain an interactive shell session. The screen
session terminates when the command that it runs terminates, no matter whether it's a command given on the command line of screen
, or the shell that it otherwise runs.
You have two issues:
- You want to run more than a single command.
- You want the session to not terminate at the end, but instead leave you in an interactive shell session, within
screen
.
To solve the first of these, make the command that screen
starts be
sh -c 'hostname; echo yes; echo no'
This is a single command that starts an in-line sh -c
script. This script runs your commands. You may want to use bash -c
in place of sh -c
if the script you're running requires bash
(your example does not).
To solve the second issue, consider starting an interactive shell as the last step in the list of commands that the sh -c
script runs:
sh -c 'hostname; echo yes; echo no; exec bash -i'
The exec bash -i
starts an interactive bash
shell session (the exec
makes it replace the sh -c
shell).
Running this within a screen
session:
screen sh -c 'hostname; echo yes; echo no; exec bash -i'
GNU screen
will terminate once the bash -i
shell session terminates.
screen
a command to run instead of a shell, it will run that command and then terminate, just like it would otherwise run your shell and then terminate when the shell exits. You could try launching a shell as the last command, but I'm currently uncertain whether it understands a list of;
-delimited commands at all (can't test at the moment).