I want to open multiple sessions in one main session with a screen command, and I can do that after opening the main session and then press on the keyboard (CTRL + A + c) but I don't want this way I want to do this using the command line only because I create a script to open the main session with multiple sub-session, so how can I achieve this. And thanks in advance :)
-
CTRL+A+C creates a new window, not a new screen session.By "sub-session", do you mean a full screen session within another screen session, or just a shell within a screen session? (BTW, I've found that tmux is more powerful and versatile than screen, and easier to operate from the command line. If you haven't gotten very comfortable with screen yet, you might consider switching.)Keith Thompson– Keith Thompson2020-05-14 04:12:14 +00:00Commented May 14, 2020 at 4:12
-
Yeah CTRL+A+C create a new window inside session then it became nested session, righ?, I mean when I need used nest session manually I open one screen session after that I create session with CTRL+A+C to get benefit of shortcut keys options with nested sesion. tmux? Never heard about it before, right now I need screen :D @KeithThompson thank you :)Mamoun– Mamoun2020-05-14 04:32:51 +00:00Commented May 14, 2020 at 4:32
2 Answers
CTRL+A+C doesn't create a new screen session. It creates a new window within the current session.
(With a little environment trickery, you could create a nested screen session within an existing screen session, where the outer screen session and the inner screen session could each have multiple windows, but that's probably not what you want to do.)
Each window within a screen session runs a command. By default, that command is your login shell. Thus you can have multiple shell processes running simultaneously and switch between them.
From any of those shells, you can create a new window under the current screen session using the screen command. It uses the $STY environment variable to recognize that it's inside an existing session, which tells it to create a new window rather than starting a new session. You could also type, for example, screen vi to launch a new window running the vi editor.
All this is covered in the screen documentation (info screen or man screen).
(Personally, I used screen for a long time, but then switched to tmux, which I find to be more flexible, more powerful, and easier to control from the command line. If you haven't invested a lot of time learning screen, you might consider switching. Or not; it's up to you, of course.)