I've got a script that uses find
to look for files that match user input. Basically, the user enters something like test*
and it's supposed to find all matching files.
The problem I'm having is that if there is a file in the current directory that matches the filename pattern the user entered, it only looks for that file. That is, if the user enters fred*
and there is a file in the current directory called frederica
, the script only ever finds files named frederica. Here's an example of the problem:
>ls
test1 test2 test3 test4 test5 words
>tmp()
> {
> my_file="$1"
> find . -iname "$my_file"
> }
>tmp test*
./test1
>
If I enter tmp test*
, I would expect it to return the five files test1 through test5. Instead it only returns the first one. Further, if I searched on, say, /
, it would still only ever return files named test1 from every directory.
The actual script is more complex, of course, and I've developed a workaround involving a "wildcard option" (e.g., -w 1
means leading and trailing asterisks, etc.) but I'd really just like to be able to let the user enter a filename with a wildcard.
Thanks in advance