I tried the following and it didn't work one bit.

find . -type f -iname "*$image"

Why? Does find not expand variables?


I don't think find supports multiple extensions in that way. As per this post by Alvin Alexander, you can do it like this:

find . -type f \( -name "*.jpg" -o -name "*.png" -o -name "*.gif" \)

With using the environment variable (assuming bash is the shell):

export image="-name *.jpg -o -name *.png -o -name *.gif"
find . -type f \( $image \)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.