# Linux – How to launch multiple screen sessions from a single bash script

bashgnu-screenlinuxscript

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!

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!