Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.


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.

share|improve this question

4 Answers 4

up vote 19 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

$
share|improve this answer
4  
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
    
Works well, thanks! –  crodjer Aug 6 at 9:34

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

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

Unless you have changed the default key bindings, you can do Ctrl-a Ctrl-t, which will show the time, if you are in screen. This will work even if you have ssh:d away somewhere else, unlike the other suggestions.

share|improve this answer
1  
Why are we not upvoting this. –  AndreKR Mar 6 at 2:36

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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