Last active
September 9, 2016 01:57
-
-
Save okovalov/e26a4fb282564a6da6f50593abf05526 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
Hi guys. Recently I had a situation when a certain directory had a few more sub-directories, and | |
I needed to perform an identical list of actions for each of those sub-directories and doing that | |
manually by changing the current directory and repeatedly executing same commands was quite annoying | |
so I decided to spend half an hour and create a bash script for that purpose. | |
A particular example of the situation I had was having several virtual machines located accordingly | |
in ~/Boxes/serverOne ~/Boxes/serverTwo ~/Boxes/serverThree (I was testing ansible and was recreating and destroying vms). | |
This script asks for the confirmation as well. | |
You can find a script here https://gist.github.com/okovalov/8f3be1e1e68c47d18cb34992527492b1 | |
Example of how to use it | |
exec_command_for_dirs ~/Boxes *Provision* 'vagrant halt; vagrant destroy' | |
Here exec_command_for_dirs is ~/.bash_profile function which uses an executable | |
file ~/bin_scripts/exec_command_for_dirs.sh but that is just a more convenient way I prefer. | |
You obviously could call that script directly | |
~/bin_scripts/exec_command_for_dirs.sh ~/Boxes *Provision* 'vagrant halt; vagrant destroy' | |
Also here is my ~/.bashrc function to run it | |
exec_command_for_dirs () { ~/bin_scripts/exec_command_for_dirs.sh "$@" "$@" "$@"; } | |
Not a perfect one but it works. I hope it will help someone as it helped me. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can find a script here https://gist.github.com/okovalov/8f3be1e1e68c47d18cb34992527492b1