Check Screen Session – How to Verify If in Screen Session

consolegnu-screen

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?

Best Answer

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

$