Posts Tagged ‘ screen

Automatically start screen

This guide describes how to setup screen to automatically launch as part of a user’s shell environment. If you don’t have tmux installed, you can use a package manager. In order to launch screen with the user’s shell session we need to add a few lines of code to that user’s .bashrc file.

This command will open the .bashrc script for the current user in vim for editing.

vim ~/.bashrc

Now add the follow lines to the user’s .bashrc.

if [ $TERM != "screen" ]; then
    screen -dR; exit
fi

Now to break down what the above lines of code do:

if [ $TERM != "screen" ];“, checks the $TERM environment variable to see if screen is already running; to avoid an infinite loop of launching screen.

screen -dR; exit“, launches screen attaching to any running screen sessions; if there are no sessions of screen running then it creates a new one. exit, this closes the shell running underneath screen when the last screen session is closed.

Revisions

  • 2011-05-23: Rewritten for clarity.
  • 2012-12-11: Rewritten for clarity.