elclanrs
elclanrs

Reputation: 94101

Unix `find` on Win MSYS, no such file or directory

I'm trying run a git pull on a bunch of folders. This is what I got so far:

find . -type d -name .git \
| xargs -n 1 dirname \
| while read line; do cd $line && git pull; done

Problem is that cd doesn't work I get a bunch of errors:

sh: cd: ./project_one: No such file or directory
sh: cd: ./project_two: No such file or directory
...

But when I do cd ./project_one it works fine. What's wrong? Any ideas?

Upvotes: 1

Views: 281

Answers (2)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798746

Perform the cd and subsequent operations in a subshell so that the main process remains in the appropriate directory.

... | while read line; do ( cd $line && git pull ); done

Upvotes: 2

sampson-chen
sampson-chen

Reputation: 47267

It looks like an issue of specifying relative vs. absolute file paths. Change the . in the "find . type -d -name .git ..." part of your script to $(pwd) and directory names should be passed as absolute paths to the while loop:

find $(pwd) -type d -name .git \
| xargs -n 1 dirname \
| while read line; do cd $line && git pull; done

Try that out and it should work =)

Upvotes: 1

Related Questions