You have quoting problems.
Tip: stick an echo
in front of the command line to see what it's actually expanding to. Even more explicit, for showing exactly where each argument is separated, stick python -c "import sys; print sys.argv[1:]"
in front of the command line.
python -c "import sys; print sys.argv[1:]" \
find $FILE_DIR -name "*.*" "${exc_lst}" -type f -mtime +20 -user sh79790 -ls
outputs:
['find', '-name', '*.*', '! -path "/var/app/s2/pnl/incoming/recondata/*.*"', '-type', 'f', '-mtime', '+20', '-user', 'sh79790', '-ls']
As you can see, ! -path "/var/app/s2/pnl/incoming/recondata/*.*"
is provided as a single big argument with spaces and quotes inside it. That's what you ask for when you quote ${exc_lst}"
: don't expand. find
does not recognize this. It needs !
, -path
, and the path all as separate arguments.
Now:
echo find $FILE_DIR -name "*.*" ${exc_lst} -type f -mtime +20 -user sh79790 -ls
outputs:
find -name *.* ! -path "/var/app/s2/pnl/incoming/recondata/*.*" -type f -mtime +20 -user sh79790 -ls
As you can see, there are literal double quote characters around the pathname. It's going to exclude a path that literally contains those quotes, which won't occur.
Try defining exc_lst
without those quotes:
export exc_lst='! -path /var/app/s2/pnl/incoming/recondata/*.*'
and then using your second form:
find $FILE_DIR -name "*.*" ${exc_lst} -type f -mtime +20 -user sh79790 -ls
Luckily, the path to exclude does not contain any spaces. If it did, you would have a much harder time of accomplishing this.
Note: All my sample output is missing the first argument to find
because $FILE_DIR
is not defined in my shell (you haven't specified its value) but if it were defined it would be there.