How to know if I am in a screen of a screen?

I know how to see if I am in a screen: I have made an alias alias inscreen = 'echo $STY' .

But earlier today, I accidently type screen inside a screen without noticing it and in some way it made me make a mistake later.

Things I’ve observe when I type screen (inner screen) inside a screen (outer screen):

  1. screen -ls only shows 1 result related to that screen
  2. echo $STY is the same in both inner and outer screen
  3. ctrl + A and ctrl + D can detach from the inner screen to no screen, but when screen -r back, both inner screen and out screen exist
  4. now I can exit twice: inner screen exit -> outer screen exit

So my question is, is there anyway I could know I am in a screen of a screen?

P.S. When type screen for the first time, it will pop some text:

enter image description here

if type screen inside a screen, it won’t show these hints.

Asked By: Rick


From @geirha, a bash guru from libra irc #bash:

if you run ”screen” inside a screen, you open a new window in that screen. It does not start a nested screen.

so typing screen inside a screen, I am opening new windows.

you can switch between the windows with ctrl+a n and ctrl+a p

also, try ctrl+a :caption always

this would show a status bar indicating which window you are current in.


put caption always "%{ Mk}%-w%{ Wk}%n %t%{ Mk}%+w" in ~/.screenrc

would have a cool status bar every time you enter screen:

enter image description here

(Format specifiers customizing how the caption will look. See STRING ESCAPES in man screen)

Ctrl+a :title "hello world"

Answered By: Rick
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.