I'm writing a script which needs the name of the currently attached screen session's name if there's any.
Ctrl + A , : followed by sessionname name (1). Within a single screen session, you can also name each window. Do this by typing Ctrl + A , A then the name you want. You can view an interactive list of named windows by typing Ctrl + A , " , and select the one you want to switch to from that list.
You can use screen -x to attach a screen session that's already attached somewhere without detaching it first. This can have side effects if the other place is already attached or is in a window that is a different size than your current one.
In this blog post I'm explaining how to rename an already existing screen session. You can simply create a new screen session by executing the “screen” command. If you want a specific name for your newly creating screen session, use the “-S” switch along with the screen command.
You can specify the name you want for a window with the ' -t ' option to the screen command when the window is created (see Screen Command). To change the name after the window has been created you can use the title-string escape-sequence ( ESC k name ESC \ ) and the title command (C-a A).
You might want to check answers here: How do I display the current "session" name or "sockname" of a screen session in the status bar?
In short the $STY environment variable is what you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With