san45
san45

Reputation: 459

Open multiple screens for a list of commands

I have a file in which each line contains a shell script as shown below

sh xyz.sh arg1 arg2
sh abc.sh arg1
sh klm.sh arg1 arg2 arg3

I want each command to be executed in a separate screen, Is there an easy way to do this rather than creating screen by the command

screen -S screen1
screen -S screen2
screen -S screen3

and executing each command from the file in corresponding screens

Upvotes: 1

Views: 559

Answers (1)

Cyrus
Cyrus

Reputation: 88583

With bash:

#!/bin/bash
declare -i counter=1     # set integer attribute
while read -r line; do
  screen -dmS screen$counter sh -c "$line"
  counter=counter+1
done < file

Upvotes: 3

Related Questions