Skip to main content
Double-quote variables when you use them. Particularly $@
Source Link
Chris Davies
  • 128.5k
  • 16
  • 179
  • 325

Tested in WSL and GitBash over Win 10.

execdir from previous solutions won't work because the command will execute using the current directory as an argument, not into it.
You can just cd into the directory and do what you want.
E.g. this is what I use to update all my repos before starting to work

find $HOME/workspace/ -maxdepth 1 -type d -name "repo*" -exec bash -c "cd \"{}\" && echo ____Pulling from \"{}\" && git pull" \; 

EDIT:
If you're not on your personal PC/laptop and need more robust code, you should write a script not injectable with external commands, like:

#!/bin/sh find $HOME"$HOME/workspace/" -maxdepth 1 -type d -exec sh -c ' for dir in $@"$@" do echo ____Pulling"____Pulling from "$dir"$dir" cd $dir"$dir" git pull done' sh {} + 

Tested in WSL and GitBash over Win 10.

execdir from previous solutions won't work because the command will execute using the current directory as an argument, not into it.
You can just cd into the directory and do what you want.
E.g. this is what I use to update all my repos before starting to work

find $HOME/workspace/ -maxdepth 1 -type d -name "repo*" -exec bash -c "cd \"{}\" && echo ____Pulling from \"{}\" && git pull" \; 

EDIT:
If you're not on your personal PC/laptop and need more robust code, you should write a script not injectable with external commands, like:

#!/bin/sh find $HOME/workspace/ -maxdepth 1 -type d -exec sh -c ' for dir in $@ do echo ____Pulling from "$dir" cd $dir git pull done' sh {} + 

Tested in WSL and GitBash over Win 10.

execdir from previous solutions won't work because the command will execute using the current directory as an argument, not into it.
You can just cd into the directory and do what you want.
E.g. this is what I use to update all my repos before starting to work

find $HOME/workspace/ -maxdepth 1 -type d -name "repo*" -exec bash -c "cd \"{}\" && echo ____Pulling from \"{}\" && git pull" \; 

EDIT:
If you're not on your personal PC/laptop and need more robust code, you should write a script not injectable with external commands, like:

#!/bin/sh find "$HOME/workspace/" -maxdepth 1 -type d -exec sh -c ' for dir in "$@" do echo "____Pulling from $dir" cd "$dir" git pull done' sh {} + 
added 322 characters in body
Source Link

Tested in WSL and GitBash over Win 10.

execdir from previous solutions won't work because the command will execute using the current directory as an argument, not into it.
You can just cd into the directory and do what you want.
E.g. this is what I use to update all my repos before starting to work

find $HOME/workspace/ -maxdepth 1 -type d -name "repo*" -exec bash -c "cd \"{}\" && echo ____Pulling from \"{}\" && git pull" \; 

EDIT:
If you're not on your personal PC/laptop and need more robust code, you should write a script not injectable with external commands, like:

#!/bin/sh find $HOME/workspace/ -maxdepth 1 -type d -exec sh -c ' for dir in $@ do echo ____Pulling from "$dir" cd $dir git pull done' sh {} + 

Tested in WSL and GitBash over Win 10.

execdir from previous solutions won't work because the command will execute using the current directory as an argument, not into it.
You can just cd into the directory and do what you want.
E.g. this is what I use to update all my repos before starting to work

find $HOME/workspace/ -maxdepth 1 -type d -name "repo*" -exec bash -c "cd \"{}\" && echo ____Pulling from \"{}\" && git pull" \; 

Tested in WSL and GitBash over Win 10.

execdir from previous solutions won't work because the command will execute using the current directory as an argument, not into it.
You can just cd into the directory and do what you want.
E.g. this is what I use to update all my repos before starting to work

find $HOME/workspace/ -maxdepth 1 -type d -name "repo*" -exec bash -c "cd \"{}\" && echo ____Pulling from \"{}\" && git pull" \; 

EDIT:
If you're not on your personal PC/laptop and need more robust code, you should write a script not injectable with external commands, like:

#!/bin/sh find $HOME/workspace/ -maxdepth 1 -type d -exec sh -c ' for dir in $@ do echo ____Pulling from "$dir" cd $dir git pull done' sh {} + 
Source Link

Tested in WSL and GitBash over Win 10.

execdir from previous solutions won't work because the command will execute using the current directory as an argument, not into it.
You can just cd into the directory and do what you want.
E.g. this is what I use to update all my repos before starting to work

find $HOME/workspace/ -maxdepth 1 -type d -name "repo*" -exec bash -c "cd \"{}\" && echo ____Pulling from \"{}\" && git pull" \;