Question : Find cmd failing with "find: paths must precede expression" however works on command line.

Experts, here is my madness....

I have an array of directories that I populate.
If there is one or more elements, either apply a single prune statement or multiple prune statements.
else run the plain find statement.

The plain find statement runs, but the enhanced find statement with prune does not run.

I receive the error:
"find: paths must precede expression
Usage: find [path...] [expression]"

As you can see from my code below I print the find statement then run it.  The version I run failes with the error I provided.  But if I copy the echoed find statement it runs just fine!  :(

Please advise.
TY
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
cnt=0
        if [ ${#excludeArr[@]} -ge 1 ]; then
                for el in ${excludeArr[@]}; do
 
                        ## Recount so we can take specific action on the last element
                        element_count=${#excludeArr[@]}
#                       echo FIND COUNT:$element_count
 
                        ## when the array has only has one element do not use the or switch with prune.
                        if [ ${#excludeArr[@]} -eq 1 ];then
                                findArr=( "${findArr[@]}" "-path ${el} -prune" )
                        else
                                findArr=( "${findArr[@]}" "-path ${el} -prune -o" )
                        fi
 
                        ## remove the most recently used element.
                        unset excludeArr[$cnt]
 
                        ## Add one to the count to keep track of the element number were on.
                        cnt=`echo $cnt |awk '{printf("%02d",$NF+1)}'`
                done
 
                ## Launch find that excludes directory paths found
                echo find ${SRVNAME}/${SID} \\\( ${findArr[@]} \\\) -prune -o -mtime +13 -ls
                find ${SRVNAME}/${SID} \\\( ${findArr[@]} \\\) -prune -o -mtime +13 -ls
 
        else
 
                ## Nothing to ignore run find
                echo find ${SRVNAME}/${SID} -mtime +13 -ls
#               find ${SRVNAME}/${SID} -mtime +13 -ls
 
        fi
Open in New Window Select All

Answer : Find cmd failing with "find: paths must precede expression" however works on command line.

I think it should be
 find ${SRVNAME}/${SID} \( ${findArr[@]} \) -prune -o -mtime +13 -ls
Random Solutions  
 
programming4us programming4us