Way to create a screen windows from shell script

gnu-screenscripting

I am trying to write a script that creates a new screen session and creates 4 windows within it. I am able to create the screen session,
finding it difficult to find out how to replicate Ctrl+A+C, in script to create window.

Best Answer

Start screen in detached mode, and make it run your command inside it::

#!/bin/bash
screen -d -m -S newsession
# window 0 is created by default, show hello0 on it
screen -S newsession -p 0 -X stuff hello0
for n in {1..9}; do
  # create now window using `screen` command
  screen -S newsession -X screen $n
  screen -S newsession -p $n -X stuff hello$n
done

Now you can attach to newsession session and check that there are 10 windows and hello0 .. hello9 is displayed in each window.

Related Question