I'm doing a script in Bash which aims to clean all the junk files I may have in a directory. I created an array with all the file patterns that I want to remove.
Example
Imagine that I have a dir called temp and inside it I have files which match the patterns in the array below
fileJunk=(".inca*" ".cat*" "*Cat%" "*inca*")
Then I do a find for each one of the items as below
for j in "${fileJunk[@]}"
do
    myList=( `find temp -maxdepth 2 -type f -iname $j` )
    for z in "${myList[@]}"
    do
        rm $z >& /dev/null      
        if [ $? -eq 0 ]
        then
            echo -e "SUCCESS: File $j was deleted\n"
        fi
    done        
done
The problem is that the find command finds all the files except the ones that inca should match.
Doing this directly on the command line worked only if I enclosed *inca* with double quotes. So I've changed the array to:
fileJunk=(".inca*" ".cat*" "*Cat%" "\"*inca*\"")
This way I'm passing "*inca*" to the find command instead of *inca*. However this only works on the command line, not using the script?
More info
Just to be clear my question, by the end, is: why when I use the command find in the shell with "*inca*" it works and within the script doesn't ?
 
     
    