4

With GNU screen (version 4), why is it that the following runs perfectly fine:

$ screen -S some-name

But if I try having a slash (/) in the session name, it gives me an error about multiuser support.

$ screen -S some/name
Must run suid root for multiuser support.

If I try setting the session name from within the screen:

$ screen
C-a :sessionname some/name

I get the following error:

: bad session name 'some/name'

So apparently a / is invalid character for a session name. Looking at the man page for screen, I see nothing about invalid or reserved characters for sessionname:

‘-S sessionname’

Set the name of the new session to sessionname. This option can be used to specify a meaningful name for the session in place of the default tty.host suffix. This name identifies the session for the screen -list and screen -r commands. This option is equivalent to the sessionname command (see Session Name).

8.5 Session Name — Command: sessionname [name]

(none) Rename the current session. Note that for screen -list the name shows up with the process-id prepended. If the argument name is omitted, the name of this session is displayed. Caution: The $STY environment variable still reflects the old name. This may result in confusion. The default is constructed from the tty and host names.

Also, unmatched ' and " in the session name complain about unmatched quotes which seems to be about syntax. E.g., :sessionname 'test"' gives test" as the name. And ^A, ^B, etc. yield control characters.

What is the valid syntax or characters for a session name?

5

The purpose of assigning a name to a screen session with -S is so you can operate on that session (for example with screen -r ...) by specifying its name.

Looking at the man page under the -r option:

-r [pid.tty.host]
-r sessionowner/[pid.tty.host]
resumes a detached screen session. No other options (except com‐ binations with -d/-D) may be specified, though an optional prefix of [pid.]tty.host may be needed to distinguish between multiple detached screen sessions. The second form is used to connect to another user's screen session which runs in multiuser mode. This indicates that screen should look for sessions in another user's directory. This requires setuid-root.

So a session name with a / character is interpreted as owner/name. (This could be documented better under the -S option.)

You can do

screen -S $USER/name

which is equivalent to:

screen -S name

In some quick experiments with screen version 4.01.00, I haven't found any other special characters that are prohibited in session names. All the following:

screen -S 'foo bar'
screen -S 'foo"bar'
screen -S "foo'bar"
screen -S 'foo\bar'
screen -S "foo'bar^Xbaz"

worked correctly for me.

In the last one, the ^X was actually a literal Ctrl-X character. screen -ls shows it literally; I had to do screen -ls | cat -A to see it. I was able to resume all these sessions by specifying their names:

screen -dr 'foo bar'

etc., and the value of $STY within each session was correct.

(I don't recommend using control characters, for what I hope are obvious reasons.)

  • 1
    Screen session names correspond directly to names in the filesystem (in /var/run/screen/S-«username»/«pid».«session-name» on my system), so it's not surprising that / isn't allowed, as its an invalid character to put in a file name. Presumably, NUL wouldn't be allowed either. (Also, various parts of the manpage document the sessionowner/ syntax.) – derobert Aug 12 '14 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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