How to tell whether the shell is run in screen

Posted on In QA

How to tell whether the shell is run in screen? For example, I run screen and it starts a bash environment. How to tell in the bash, whether it is run by screen or it is a normal bash environment?

It can be identified by checking the TERM environment variable:

In a bash in screen:

[zma@localhost ~]$ env | grep TERM
TERM=screen
TERMCAP=SC|screen|VT 100/ANSI X3.64 virtual terminal:

However, in a “normal” bash environment:

[zma@localhost ~]$ env | grep TERM
TERM=xterm

“In each window’s environment screen opens, the $TERM variable is set to “screen” by default.” — screen manual https://www.systutorials.com/docs/linux/man/1-screen/

Leave a Reply

Your email address will not be published. Required fields are marked *