2

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

image=.jpg,.png,.gif
find . -type f -iname "*$image"

Why? Does find not expand variables?

1 Answer 1

2

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 \)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .