Skip to content

Instantly share code, notes, and snippets.

@bokwoon95
Last active April 30, 2024 07:43
Show Gist options
  • Save bokwoon95/5cf4696dd1bed23aa3bda591fd24849b to your computer and use it in GitHub Desktop.
Save bokwoon95/5cf4696dd1bed23aa3bda591fd24849b to your computer and use it in GitHub Desktop.
How to pass multiple arguments to arbitrary commands to run in parallel with xargs
#!/bin/sh
echo 'linux amd64 "Intel Linux"
linux arm64 "ARM Linux"
darwin amd64 "Intel macOS"
darwin arm64 "Apple Silicon macOS"
windows amd64 "Intel Windows"' | tr '\n' '\0' | xargs -0 -I{} -P4 sh -c 'f() {
echo "os=$1 arch=$2 desc=$3";
}; f {}'
os=linux arch=amd64 desc=Intel Linux
os=linux arch=arm64 desc=ARM Linux
os=darwin arch=amd64 desc=Intel macOS
os=darwin arch=arm64 desc=Apple Silicon macOS
os=windows arch=amd64 desc=Intel Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment