Created
August 5, 2020 14:43
-
-
Save mdelillo/230ea5d2407724731ff43f45f8fc7794 to your computer and use it in GitHub Desktop.
Runs a bash function on all child directories in parallel
This file contains hidden or 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
#!/usr/bin/env bash | |
set -euo pipefail | |
do_something() { | |
dir=$1 | |
echo "doing something with $dir" | |
sleep 1 | |
} | |
main() { | |
root_dir="$(cd "$(dirname "$0")" && pwd)" | |
directories_in_parallel="8" | |
find "${root_dir}" -type d -depth 1 -print0 | \ | |
xargs -0 -P${directories_in_parallel} -I {} bash -c "$(declare -f do_something) ; do_something {}" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment