Skip to content

Instantly share code, notes, and snippets.

@rojenzaman
Last active May 31, 2021 15:55
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 rojenzaman/371a6f4e980a0d68a8ca6c0fa49b9f3b to your computer and use it in GitHub Desktop.
Save rojenzaman/371a6f4e980a0d68a8ca6c0fa49b9f3b to your computer and use it in GitHub Desktop.
Run specific command or script in all sub-directories.
#!/bin/bash
cd "$(dirname "${BASH_SOURCE[0]}")"
function execute() {
cd $i
echo -e "\e[91m$x:\e[0m\e[92m`pwd`\e[0m"
case $1 in
ls) $@ --color=auto ;;
grep) $@ --color=auto ;;
fgrep) $@ --color=auto ;;
egrep) $@ --color=auto ;;
*) $@ ;;
esac
echo ""
}
x=0
for i in */; do
x=$((x+1))
( execute $@ )
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment