Search code examples
gnu-screenunix

how do you script gnu screen from within a screen session to open new windows and run commands in them?


From within a screen session, I'd like to run a shell script that opens a few new screen windows in the same session and start running some programs in them.

I need a script like this:

screen -t newWindow
[switch to newWindow and execute a command]
screen -t newWindow2
[switch to newWindow2 and execute a command]

I don't know how to accomplish the effect I describe in the brackets. Any clues? Please note that this is not a script I'll be running to start a screen session. I need this script to be runnable within an existing screen session, in order to add new windows to the session.


Solution

  • Running this script inside screen does what I think you want:

    #!/bin/bash
    
    screen vi
    screen top