Question : unix find command fails in script - works on command line

Hi, in a script I construct a find command like this:

FIND_EXEC="find /cygdrive/d/tmp -maxdepth ${MAXDEPTH} -mindepth 1 -name ${PATTERN} -type ${FILETYPE} -mmin +${FILE_AGE} -print0 | xargs -0  "

This yields the following line:
find /cygdrive/d/tmp -maxdepth 2 -mindepth 1 -name "20*" -type d -mmin +2
880 -print0 | xargs -0

which executes nicely. But if I call the vairable $FIND_EXEC in my script, find says:
find: paths must precede expression: |

This is not the common name globbing problem as it remains if I remove the name parameter entirely. I suppose this is a shell escaping problem, but escaping the pipe \| did not help.
Any ideas?

Answer : unix find command fails in script - works on command line

Hi. In your script add: set -x for debugging, and eventually set -v for verbose, then try to run the script. You will see the answer. The problem is the pipe used before xargs.

Try something like that:

FIND_EXEC="find /cygdrive/d/tmp -maxdepth ${MAXDEPTH} -mindepth 1 -name ${PATTERN} -type ${FILETYPE} -mmin +${FILE_AGE} -print0"
PIPE="xargs -0"

$FIND_EXEC | $PIPE


OR

Replace the double quotes by single quotes and then do echo $FIND_EXEC instead of $FIND_EXEC


FIND_EXEC=`find /cygdrive/d/tmp -maxdepth ${MAXDEPTH} -mindepth 1 -name ${PATTERN} -type ${FILETYPE} -mmin +${FILE_AGE} -print0 | xargs -0 `

echo $FIND_EXEC

Good luck!
Random Solutions  
 
programming4us programming4us