Home > Mobile >  Running shell scripts in parallel from a list of files
Running shell scripts in parallel from a list of files

Time:12-01

I have a list of scripts doing their own thing (they are actually Rscripts reading modifying and writing files) like this:

## Script 1
echo "1" > file1.out
## Script 2
echo "2" > file2.out
## Script 3
echo "3" > file3.out

These are saved in different scripts as follow:

## Writing script 1
echo "echo \"1\" > file1.out" > script1.task
## Writing script 2
echo "echo \"2\" > file2.out" > script2.task
## Writing script 3
echo "echo \"3\" > file3.out" > script3.task

Is there a way to run all these scripts in parallel using the file names? In a loop it'd look like this:

for task_file in *.task
do
  sh ${task_file}
done

CodePudding user response:

Following advice from Andre Wildberg and user1934428 here's a solution using & just for the record:

for task_file in *.task
do
  sh ${task_file} &
done
wait
  • Related