I’m trying to make a script to create four terminals, each running its own instance of screen, send a bash command (top in my example) to the first, and then link that session to each of the others. See the end of the post for why I would ever want to do that.
Anyway, it does almost what I want it to; I end up with four terminals each running their own properly named instance of screen, and all but the last one linked to the original session. But not that last one. So here’s the code, and I’m hoping someone can let me know why it’s not behaving as expected:
#!/bin/bash
for i in {1..4}
do
gnome-terminal --window-with-profile=hdesk$i -e 'screen -S hdesk'$i
done
screen -XS hdesk1 stuff 'top^M'
for i in {2..4}
do
screen -XS hdesk$i stuff 'screen -x hdesk1^M'
done
I tried doing the same line by line from a terminal instead of running it as a script and it worked fine. For some reason the session ‘hdesk4’, while it exists, isn’t attaching ‘hdesk1’.
As for why, I’m using compiz, and I want this terminal to be sticky (present on all virutal desktops). But I have eight virtual desktops in two rows of four, and I don’t want this sticky on the top row, just the bottom, so I can’t just set a single terminal to be sticky. So any solution that achieves that goal but avoids this screen mess altogether would also be welcome.
edit: It now works, although I made no changes to the code or to anything else between the not working and the working. Just suspended my computer overnight and unsuspended.
I’ve tried your code, came up with this:
I have no idea why this works, maybe
screenrefuses to attach too fast?