Created
July 22, 2022 16:38
-
-
Save mfansler/4f86e0c86030e3fe7cc2a576fa71e797 to your computer and use it in GitHub Desktop.
Notes on xargs syntax for parallel execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## space-separated input | |
## -n1: run each separately | |
## -P6: run up to 6 in parallel | |
## -I '{}': replace {} with argument | |
## \$ delays evaluation to bash execution | |
## waits randomly for up to five seconds, then prints | |
echo {1..12} |\ | |
xargs -n1 -P6 -I '{}' \ | |
bash -c "sleep \$[ \$RANDOM % 5 ]; echo {}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment