Skip to content

Instantly share code, notes, and snippets.

@mfansler
Created July 22, 2022 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfansler/4f86e0c86030e3fe7cc2a576fa71e797 to your computer and use it in GitHub Desktop.
Save mfansler/4f86e0c86030e3fe7cc2a576fa71e797 to your computer and use it in GitHub Desktop.
Notes on xargs syntax for parallel execution
#!/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