Making bash automatically attach screen when you login sounds cool. However, it's fraught with peril: what if screen breaks and you can't get a shell to fix it? What if screen gets attached when you preform operations like scp, or use the system system call?

update I've been using this for quite a while, and it hasn't caused me any problems yet.

setting it up

Here's the solution I'm devising for this.

Put the following in your .bashrc.

if [ `uname -n` = 'lefschetz' -a \
     `expr index $- i` != 0 -a \
     x"$SHLVL" = x1 -a \
     ! -e dont_start_screen ]; then
    screen -x main
fi

fixing it if it breaks

If screen hangs, you have a problem. To make screen not start, this works:

ssh -t lefschetz bash

This makes it allocate a tty, but screen doesn't start because SHLVL is 2 since it's been invoked through another shell.

DebianNotes/BashScreenAutoattach (last edited 2009-05-14 18:25:33 by dyn-160-39-55-73)