How can I tell whether I'm in a screen? How can I tell whether I'm in a screen? linux linux

How can I tell whether I'm in a screen?


Check $STY. If it's null, you're on a "real" terminal. If it contains anything, it's the name of the screen you're in.

If you are not in screen:

eric@dev ~ $ echo $STYeric@dev ~ $ 

If you are in screen:

eric@dev ~ $ echo $STY2026.pts-0.ip-10-0-1-71


Another way I've done it is to echo $TERM.

 $ echo $TERM screen

Since I end up doing this a lot, I added an alias into my .bashrc file:

alias trm='echo $TERM'

This way, whether in screen or not, if I just execute 'trm' it will show me whether I'm in SCREEN or elsewhere (usually XTERM).


Alternative approach to check if you are in screen.

type:

Ctrl-a ?

If you see the screen help you are in screen.

Otherwise you'll get a question mark '?' on the prompt.