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
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'
exec bash -i starts an interactive
bash shell session (the
exec makes it replace the
sh -c shell).
Running this within a
screen sh -c 'hostname; echo yes; echo no; exec bash -i'
screen will terminate once the
bash -i shell session terminates.