How to check if I'm in screen session?

I need it to determine if hitting ctrl+d would disconnect me from server or just close current screen.

Is it somehow possible to check if I'm right now in screen session?


You can look at the $STY variable (a variable set by the screen command). If it is not "" then you are in a screen session.

I am in screen

$ echo $STY 
29624.pts-1.iain-10-04
$

I am not in screen

$ echo $STY

$

You can look at the $TERM variable.

echo $TERM

If it's a screen session, the term variable should return "screen".

root@deore:/volumes# echo $TERM
screen

Ctrl-a -d (to exit screen)

root@deore:/volumes# echo $TERM
xterm

Also check: https://stackoverflow.com/questions/3472287/how-do-you-tell-if-the-current-terminal-session-is-in-gnu-screen