How to execute parallel commands

Im working on a big project and we have a few npm packages.

I want to install all packages in parallel, which means that I want all of them to start at the same time (to save time), and as soon as the last installation was completed, to continue working with my script.

Sample 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 

I’m not going to accept the fastest answer, but the one who will do what I want to do and don’t have the right knowledge on how to do this so that you can tell about the time and give a complete answer.

Thank you in advance.

+4
source share
1 answer

npm install :

npm install &

done :

wait

bash manual:

, , , , . , . , , .

+4

Source: https://habr.com/ru/post/1622392/


All Articles