문제

I am trying to write a csh script which will execute a makefile in child directories when present. So far I have this:

find -maxdepth 2 -name 'Makefile' -print -execdir make \;

The issue I'm facing is that I get the following error when I try to run it:

find: The current directory is included in the PATH environment variable, which is insecure in combination with the -execdir action of find. Please remove the current directory from your $PATH (that is, remove "." or leading or trailing colons)

I cannot reasonably change the $PATH variable in this case. Any ideas on a workaround.

Many thanks and happy coding

도움이 되었습니까?

해결책

The -execdir flag is a feature of GNU find, and the way it's implemented is to throw that error and refuse to proceed if the situation it describes is detected. There's no option in find to avoid that error. So, you can either fix PATH (you can do that just for the find command itself:

 PATH=<fixed-path> find -maxdepth 2 -name 'Makefile' -print -execdir make \;

) or else don't use -execdir as described by Basile.

Err... actually that's POSIX sh syntax. Does csh support that? I haven't used csh in so long that I can't remember, and honestly it's such a bad shell that I can't be bothered to go look :-p :-)

다른 팁

You could try

  find -maxdepth 2 -name 'Makefile' \
       -exec sh -c "make -C $(dirname {})" \;

or (using sh syntax)

  for m in  Makefile */Makefile */*/Makefile ; do
     if [ -f "$m" ]; then 
        make -C $(dirname $m)
     fi
  done
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top