Skip to content

Instantly share code, notes, and snippets.

@risadams
Created February 1, 2024 12:13
Show Gist options
  • Save risadams/f87620a1e732528b0dd84b6a61ac6585 to your computer and use it in GitHub Desktop.
Save risadams/f87620a1e732528b0dd84b6a61ac6585 to your computer and use it in GitHub Desktop.
execute a command in parallel
#!/bin/env bash
rip() {
local cmd=$1 # Target command
local max_proc=$(($(nproc) / 2))
mapfile -t args < <(printf '%s\n' "${@:2}")
printf '%s\n' "${args[@]}" | xargs --verbose -I % -P $max_proc bash -c "${cmd} %"
}
# Example usage
mapfile -t rpms < <(find "$HOME/src" -name '*.rpm')
rip echo "${rpms[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment