-
-
Save internalsystemerror/814c042f558b903690589e7d3e835760 to your computer and use it in GitHub Desktop.
Bash script to execute a given command in all subdirectories of the current 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
#!/usr/bin/env bash | |
set -e | |
trap "exit" INT | |
USAGE="Usage: | |
fesd <command>" | |
# show help if requested | |
if [ "x$1" == "x-h" ] || [ "x$1" == "x-?" ] || [ "x$1" == "x--help" ]; then | |
echo "Execute command in each subdirectory of current directory." | |
echo "$USAGE" | |
exit 0 | |
fi | |
# assert arguments supplied | |
if [ "x$1" == "x" ]; then | |
echo "No input, 'fesd -h' for help" | |
echo "$USAGE" | |
exit 1 | |
fi | |
# execute commands | |
for DIR in $(find . -maxdepth 1 -mindepth 1 -type d -not -path '*/.*' | sed "s|^\./||" | sort); do | |
echo "======== entering $DIR ========" | |
(cd "$DIR" && bash -c "$*") | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment