is it somehow possible to check if I'm right now in screen session? I need it to determine if hitting ctrl+d would disconnect me from server or just close current screen. Thanks.

link|improve this question

75% accept rate
feedback

3 Answers

up vote 7 down vote accepted

You can look at the $STY variable. 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

$
link|improve this answer
This presumes that you are still within a running session on the local computer. If you start up screen and then SSH somewhere else, this won't work. – David Mackintosh Apr 11 '11 at 3:05
feedback

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: http://stackoverflow.com/questions/3472287/how-do-you-tell-if-the-current-terminal-session-is-in-gnu-screen

link|improve this answer
This presumes that you are not deliberately messing with your TERM value for some reason. – David Mackintosh Apr 11 '11 at 3:04
feedback

I have found another solution:
Modify your .screenrc, so my screen session looks completely different from normal terminal.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.