Skip to content

Instantly share code, notes, and snippets.

@DanielFGray
Last active September 28, 2018 18:34
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 DanielFGray/5f8ffaeec00f6a61cbbcedbf6e44d791 to your computer and use it in GitHub Desktop.
Save DanielFGray/5f8ffaeec00f6a61cbbcedbf6e44d791 to your computer and use it in GitHub Desktop.
multiple () {
local l x y p c
c=0 p=0 l=()
while :; do
case $1 in
-p)
if [[ $2 = -* ]]; then
echo '-p requires an argument'
return
fi
p="$2"
shift ;;
--) shift; break ;;
*) l+=("$1") ;;
esac
shift
done
echo
if (( p > 1 )); then
for y in "${l[@]}"; do
(( c++ >= p )) && wait -n
echo "$* $y"
"$@" "$y" &
done
wait
else
for y in "${l[@]}"; do
echo "$* $y"
"$@" "$y"
done
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment