0

I am trying to use find so it would find a script file and if found execute it in the same directory it found it in.

Something like this:

find . -name "CLEAN" -execdir "CLEAN" {} \;

except {} is the found file itself, which is not what I want.

1

May I suggest:

find . -type f -name "CLEAN" -execdir ./CLEAN \;

and in CLEAN, set your pwd rather than having it passed:

#!/bin/sh

MYDIR=`pwd`
echo "${MYDIR}"
  • I get this: 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) – SFbay007 Mar 19 '15 at 5:01
  • Changed the $PATH to not include . and it worked..thanks! – SFbay007 Mar 19 '15 at 5:07
  • Good to hear! Keep in mind that there are some security concerns, especially if the above gets run by root in any user-controlled directories, as they could create their own scripts and have them run as root, but I'll assume that you are on top of that. – Ric F Mar 19 '15 at 5:13
0

if "CLEAN" is shell script file

than this work

  find . -name "CLEAN.sh" -execdir sh -c './CLEAN.sh' sh {} \;

this command file CLEAN.sh and it execute in finding directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.