for ... do - syntax

hi!

pls help me :slight_smile:

cd folder
for f in *; do
 ...
done

this circle takes all files from folder1
i need only .pdf files
but it may be like a.pdf or a.PDF

what syntax must i use?

smth like it:

cd folder
for f in *.(pdf|PDF); do
 ...
done

PS. - it doesn't work.

try

for f in *.@(pdf|PDF); do
...
done

---------- Post updated at 03:23 PM ---------- Previous update was at 03:13 PM ----------

Watch out : if your file is Pdf or pDf you will miss it !

Consider the following examples :

# ls -1 ?.*
a.pdf
b.Pdf
c.pDF
d.PDF
e.dFp
# for i in *.[pPdDfF]??;do echo $i;done
a.pdf
b.Pdf
c.pDF
d.PDF
e.dFp
# for i in *.[pP][dD][fF];do echo $i;done
a.pdf
b.Pdf
c.pDF
d.PDF
# for i in *.@(pdf|PDF);do echo $i;done
a.pdf
d.PDF

In red , the most accurate matching... depending on your needs

shopt -s nocaseglob
for file in  *.pdf
do
  ....
done

Or Ruby(1.9+) if you have it

$ ruby -e 'Dir.glob("*.pdf", File::FNM_CASEFOLD).each {|x| puts x }'