0

I have the need to pass multiple parameters to find dynamically. I'm doing that using this function:

GEN_FIND_PARAMS() {
    PARAM=""

    for WORD in $1; do
        ADD=""

        if [ X"$PARAM" != "X" ]; then
            ADD="-o"
        fi
        ADD="-name '$WORD' $ADD"

        PARAM="$ADD $PARAM"
    done

    echo $PARAM
}

If I run the function by itself, I get correct results:

SHD_FILES="*.rev *.db *.cdb"
GEN_FIND_PARAMS "$SHD_FILES"

Outputs correctly

-name '*.rev' -o -name '*.db' -o -name '*.cdb'

However, when I using it fully, it just doesn't find anything:

find /dev/shm $(GEN_FIND_PARAMS "$SHD_FILES")

Outputs nothing, even though I know the files are there, because running it plainly works:

find /dev/shm -name '*.rev' -o -name '*.db' -o -name '*.cdb'

Is there something wrong in the value substitution? I'm also open to other ways to do this (there must be a better one)

0 Answers0