user8125 user8125 - 1 year ago 43
Bash Question

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

When using screen in linux, how can I tell if I'm in a screen or not?
I could do

and I'll exit a screen if I was in one, but if I wasn't, then I'll end up closing my terminal.

When doing
screen -r
, I could see if I have other screens attached, but how do I know if my current terminal is one of those attached screens?

jho jho
Answer Source

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 $STY
eric@dev ~ $ 

If you are in screen:

eric@dev ~ $ echo $STY