Join the "screen" session to create a new screen window

I have a multi-window screen session. I want to connect to it, create a new window in it and start the shell in this new window.

Question: How to do this from the command line outside the screen session?

I've tried a lot, for example. Mr. screen -x (but it joins one of the existing screen windows, it does not create a new one and does not launch a new shell). Any hints are welcome.

The environment is Linux (Ubuntu 12.04).

+6
source share
3 answers

I found something on the mailing list, thanks tuxuday :)

I am doing it now as follows:

 #!/bin/bash screen -X screen -t NEWWINDOW # create new window (switches existing attached terminal) sleep 0.1 screen -X other # switch existing attached terminal back to its old window sleep 0.1 gnome-terminal -e 'screen -x -p NEWWINDOW' # connect to new window 

I'm not sure what is sleeping, maybe they are not needed in all environments, but I can easily wait for these 0.2s.

My .bash_aliases changes the title of the screen window with a delay, so the inconvenient NEWWINDOW will not be delayed for long (and thus will not prevent further calls to this script).

+6
source

Add a new split window to sesion_name and run command

 screen -S sesion_name -x -X screen bash -c 'command; exec bash' 
+3
source

To select a window to connect, use the -p option. Giving + will create a new one, so your command is simply:

 screen -x session_name -p + 

This is documented on the manual page:

-p n̲u̲m̲b̲e̲r̲_o̲r̲_n̲a̲m̲e̲ | - | ̲ = ̲ | ̲ + ̲

 Preselect a window. This is useful when you want to reattach to a specific windor or you want to send a command via the "-X" option to a specific window. As with screen select commant, "-" selects the blank window. As a special case for reattach, "=" brings up the windowlist on the blank window. 
+2
source

Source: https://habr.com/ru/post/915784/


All Articles