Created
June 6, 2023 09:04
-
-
Save wojtekmaj/06f534a98d5ac0090866917dd2051fe6 to your computer and use it in GitHub Desktop.
Run a given script for each Git repository in the given directory
This file contains 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
# Sample usage: bash ./foreach.sh ./update-dependencies.sh | |
script_dir=$(dirname -- "$( readlink -f -- "$0"; )") | |
echo "Running script $1 for each repository" | |
# Find all Git repositories, skipping node_modules directories | |
find . -maxdepth 4 -name ".git" -print0 | while read -d $'\0' repo; do | |
echo "Processing ${repo%/.git}" | |
# Go to the repository directory | |
cd "${repo%/.git}" | |
echo " Running $1" | |
# Make the $1 path relative to foreach.sh and run it | |
bash "$script_dir/$1" | |
echo " Done" | |
# Go back to the previous directory | |
cd - > /dev/null | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment