24

What's the best way to have screen automatically run when you open a new shell, whether by login, xterm, or anything else?

I see the most common recommendation is to put exec screen in your regular shell's rc or login/profile file, but for, for example, tcsh, login shells run .login last, while non-login shells read .cshrc last. If I put exec screen in .cshrc, login shells won't source the .login file, and if I put it in .login, non-login shells won't run screen. I assume that there are similar issues with other shells.

1
  • 1
    This does not answer the question, but it is worth a mention: tmux is a revolutionary step up from screen and tries to be close to keyboard compatible with screen. This page documents how to start it automatically from .bashrc.
    – datashaman
    Nov 14, 2012 at 17:32

4 Answers 4

20

One way is:

# if $STY is not set...
if [ -z "$STY" ]; then
    exec screen -ARR
fi

Note that this is written for bash, but should be similar for csh too. Put it to .cshrc to be executed for all shells.


Another way: You can simply set screen as your login shell in /etc/passwd itself, and put this line to your ~/.screenrc: (Fix the path, of course.)

defshell /bin/csh

But this may break programs which run the login shell defined in /etc/passwd for various commands.

(Edit: Don't forget to add screen to /etc/shells)

1
  • 1
    Didn't know about the STY variable before, and while looking it up in screen manual, I also found that you can execute screen with-in screen to run commands in a new window (e.g., "screen vi" will open vi in a new window, without a controlling shell). BTW, for csh, you would put it in .login file not .cshrc, you don't want it to run for "all" shells. Samething applies to bash, put it in .profile or .bash_login, not in .bashrc.
    – haridsv
    Mar 24, 2011 at 0:11
3

Old question, but googling for the same thing brought me here so here's a response for anyone else that stumbles onto this page.

Best thing I've found so far is byobu if your distro has it. Comes with an option to run at login and controls multiple screens at once.

You can detach and log out at one location then login to the same session at another location.

I find screen is great to use for running server processes but byobu is great for everyday things.

-1

I usually do this in my ~/.screenrc

defshell -bash  # the dash makes it a login shell
-2

How about using chsh:

chsh /usr/bin/screen

This sets the default login shell in /etc/passwd. (you could it it there, too)

1
  • It then becomes hard to do anything with your account other than log in. Also, your sysadmin probably doesn't have screen in /etc/shells. Also, see the accepted answer.
    – wfaulk
    Aug 21, 2012 at 13:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .