Created
September 9, 2016 01:49
-
-
Save okovalov/8f3be1e1e68c47d18cb34992527492b1 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
if [ -z "$1" ] | |
then | |
echo "No destination path is given" | |
exit 1 | |
fi | |
if [ -z "$2" ] | |
then | |
echo "No folder name pattern is given" | |
exit 1 | |
fi | |
if [ -z "$3" ] | |
then | |
echo "No command is given" | |
exit 1 | |
fi | |
destination=$1 | |
namepattern=$2 | |
command=$3 | |
printf "Searching for pattern $namepattern in $destination\n\n" | |
for dir in `find $destination -name $2 -type d` | |
do | |
cd $dir | |
echo "Target directory is '$dir'" | |
echo "Executing command: $command" | |
read -p "Are you sure? [y/n] " -n 1 -r | |
echo # (optional) move to a new line | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
eval "$command" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please see https://gist.github.com/okovalov/e26a4fb282564a6da6f50593abf05526 for the explanation