Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've written a script (that doesn't work) that looks something like this:

#!/bin/sh

screen -dmS "somename" somecommand

for i in {0..5}; do
    screen -dmS "name$i" anothercommand $i
done

For some reason, if I copy and paste this into a terminal, it creates 7 detached screen sessions as I expect. If I run it from within a script, however, I get only the first session, "somename," when I run screen -ls.

Edit: If the same can be accomplished another way (e.g. with multiple screen windows instead of sessions), I would be open those solutions as well. Thanks!

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

I ended up taking this question to StackOverflow, where Brian Gerard answered the question. The {0..5} loop syntax is bash (3.x+) specific. By default, my system was setup to run some other shell from /bin/sh, so I changed my sharp-bang to #!/bin/bash and my problem was solved!

share|improve this answer
    
For the reference, this is the answer on SO. –  koniiiik May 9 '13 at 13:36
add comment

Why do your need to open so screen session. Instead why dont your try creating multiple window (i mean as a part of single screen terminal window) inside single screen. And switch between them with ctrl-a 1 or 2 or 3 , etc depending upon how many you have created and want to view the output. This sounds bad approach to running screen. In case you have not read multiple windows in screen read up any tutorial on screen in web. Screen main design goal is window mulitplexing. So not just attach and dettach.

share|improve this answer
1  
Exactly, screen is really designed to have one master session managing multiple terminal sessions. No need to spawn multiple master screens. –  Keith Jul 11 '11 at 2:06
    
Ok, good advice. I would certainly like to take advantage of the windows within a single screen session. Any idea how I would do this in an automated fashion from my script (to accomplish the same as the above script)? –  Eric Jul 11 '11 at 15:17
add comment

I don't really know why your script does not work but another way to start multiple screen sessions is to create a custom screen config file. It was discussed in this AskUbuntu question: http://askubuntu.com/questions/49245/start-multiple-apps-running-in-shells-split-in-one-console

I guess you could simply create the config file test.conf with the following content and launch screen -d -c test.conf

screen -S "somename" somecommand
screen -S "name1" anothercommand 1
screen -S "name2" anothercommand 2
...

And if it works, then your script could first create this test.conf file and customize it in the loop with

echo "screen -S "name$i" anothercommand $i" >> test.conf

and then start screen -d -c test.conf at the end of script.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.