I have a script in which I am attempting to match strings in filenames on either side of a word. The keywords which are meant for pattern matchin with the wildcard character, as in:
ls *spin*.txt
This will of course match any of the following filenames:
one_spin.txt
4_5342spin-yyy.txt
fifty_spinout.txt
...etc.
What I would like to do is use the word 'spin' and a number of other words as match cases in an array that I can pass through a loop. I'd like these matches to be case-insensitive I attempt this like so:
types=(spin wheel rotation)
for file in $types; do
ls '*'${file}'*.txt'
done
EDIT: Because I'm looking for a solution that is maleable, I'd also like to be able to do something like:
types=(spin wheel rotation)
for file in $types; do
find . -iname "*$file*.txt"
done
I'm not sure how bash interprets either of these except seeing that it does not list the desired files. Can someone clarify what is happening in my script, and offer a solution that meets the aforementioned criteria?