Skip to content

Instantly share code, notes, and snippets.

@gmale
Created April 23, 2013 18:56
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 gmale/5446371 to your computer and use it in GitHub Desktop.
Save gmale/5446371 to your computer and use it in GitHub Desktop.
For Each Folder. For each folder, run a given shell command. I use this to switch some (but not all) submodules to a particular branch. As in: bash$ fef ag-api ag-bizniz ag-data ag-data-commons Folders: ag-api ag-bizniz ag-data ag-data-commons Enter the command you'd like to run in each of these folders: git checkout feature/SID-578-add-timely-s…
#!/bin/bash
folders=$@
echo -e "\nFolders: $folders"
read -p "Enter the command you'd like to run in each of these folders: " commands
echo
for f in $folders
do
echo -e "\nEntering $f..."
cd $f 2> /dev/null
[[ $? -eq 0 ]] || { echo -e "\tFailed to find directory $f"; continue; }
bash -c "$commands"
cd - &> /dev/null
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment