Bash – GNU Screen and .bashrc

bashbashrcgnu-screen

I am trying to launch GNU Screen using my .bashrc. I'm almost there:

if [ -z "$STY" ]; then
   exec screen -dR
else
   exec gnome-terminal
fi

This is wrong though! The first case works, screen launches when I open a terminal. But the second part fails. I want to open a regular terminal if I already have one open. But this just opens an infinite number of terminals…

Best Answer

You could try (after the else):

if [ "$HAS_STARTED_TERM"!="1"]; then
    HAS_STARTED_TERM=1
    export HAS_STARTED_TERM
    exec gnome-terminal
fi