Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you tell if the current terminal session is in GNU screen?

I have a command I want to execute in .bashrc only when the current terminal window is managed by GNU screen. How do I do this? Is there an environment variable for it? I used to have

if [ -n "$WINDOW" ]; then
    command
fi

But from what I can tell, $WINDOW may or may not be defined across all screen managed sessions.

like image 445
OTZ Avatar asked Aug 12 '10 21:08

OTZ


2 Answers

Check for the environment variable $STY (contains info about the screen) or for $TERM being 'screen' (probably less reliable).

like image 143
signine Avatar answered Oct 14 '22 13:10

signine


signine is correct

See the doc

http://www.gnu.org/software/screen/manual/html_node/Environment.html

STY

Alternate socket name. If screen is invoked, and the environment variable STY is set, then it creates only a window in the running screen session rather than starting a new session.

like image 24
rhlee Avatar answered Oct 14 '22 14:10

rhlee