The following doesn’t work given second command doesn’t run until first exits and when I try running first in background using &, I get following error.

I also tried running first in background using -d -m, but split doesn’t work.

Must be connected to a terminal.

screen -S test -t foo long_lived_process_1
screen -S test -X split
screen -S test -X focus down
screen -S test -X screen -t bar long_lived_process_2
  • 1
    tmux could probably solve it: lukaszwrobel.pl/blog/… - section "scripting tmux"
    – Jan
    Apr 21, 2021 at 11:52
  • 1
    Thanks @Jan... looking into tmux.
    – sunknudsen
    Apr 21, 2021 at 12:06
  • 1
    +1 for tmux. a good summary of tmux-vs-screen: mutelight.org/practical-tmux (contains also lots of exemples of config). screen is a wonderful tool (and quite ancient) but tmux is more recent and offers some benefits (maybe less portable though, and could introduce differences, some which are listed in the link I provided) Apr 21, 2021 at 12:40
  • 1
    Problem solved using tmux. Still curious to know if this is possible using screen.
    – sunknudsen
    Apr 21, 2021 at 13:04

1 Answer 1


With screen -S test some command, it opens the screen right there, instead of sending it to the background. So, the script running those commands stops, the next commands don't get executed against that screen.

So, I guess we have to send it to the background initially, and then send the other commands.

screen -S test -d -m top 
screen -S test -X title foo
screen -S test -X split
screen -S test -X focus down
screen -S test -X screen -t bar watch free
screen -S test -R 

I didn't get -S test -d -m -t foo top to work, the title didn't catch, but the first window is a bit of a special case anyway. (Unless you just decide to keep it as a dummy and run -X select 0, -X kill at the end.)

You could also look at putting the commands in screenrc, there's examples in the man page about doing setup like this through that.

  • Thanks so much for helping out again. I naively used ls as an example... both commands are long lived so screen would not terminate (updated question).
    – sunknudsen
    Apr 21, 2021 at 11:33
  • "exists" or "exits"? Apr 21, 2021 at 11:36
  • @sunknudsen, right, I got it wrong, starting the first window brings the whole screen to the foreground. Edited.
    – ilkkachu
    Apr 21, 2021 at 14:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .