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

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


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


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.


check $TERM, it is set to 'screen' in screen session.. (but not 100% guaranteed)

UPDATE

alternatively, you can utilize the fact that in screen, $TERMCAP contains screen substring:

[[ $TERMCAP =~ screen ]] && echo "in screen"

also not 100% guaranteed

UPDATE2

if neither approach works, you can find some inspiration in screen manual