4

Im working on large project and we have multiple npm packages.

I want to install all the packages in parallel which mean that i want all of to run on the same time (to save time) and once the last install has finished to continue with my script.

Example script:

#!/bin/zsh #... NPM_FOLDERS=( common.library/audit common.library/cipher common.library/logger ... ) # Get the number of total folders to process counter=${#NPM_FOLDERS[@]}; # counter for user feedback to the current install folder index index=1; # loop and install all the required packages for folder in $NPM_FOLDERS; do # Print the installation message with the folder & couters echo "\033[38;5;255m($index/$counter) Executing npm install in: \033[38;5;226m$folder"; # change the folder to the required location cd $ROOT_FOLDER/$folder; # Execute install on this folder npm install ; # increase current index let index++; done echo echo "\033[38;5;11mInstallation completed." echo 

In not going to accept the fastest answer but the one who will do what i wish to do and do not have the right knowledge on how to do it, so you can tale the time and give a full answer.

Thank you very much in advance.

1
  • npm install &? Not sure how to explicitly wait for background processes, though. Commented Dec 31, 2015 at 23:32

1 Answer 1

5

Execute npm install in the background with:

npm install & 

Then after the done line you can wait for all the background processes to finish with:

wait 

This command is explained in the bash manual:

Wait until the child process specified by each process ID pid or job specification jobspec exits and return the exit status of the last command waited for. If a job spec is given, all processes in the job are waited for. If no arguments are given, all currently active child processes are waited for, and the return status is zero.

Sign up to request clarification or add additional context in comments.

12 Comments

But this will not wait until the last one will install. i need to install 20+ process and wait until the last one will finish. will it work?
What will the wait do? will it wait for all the processes?
If you run wait with no arguments, it waits for all background processes.
It waits for all background processes to finish, just like I said in the answer.
I've added an excerpt from the documentation, because you don't know how to google.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.