First of all, are you sure that the regular expression you give in your example is what you want to get? (0 or more "a"s followed by "sampl" and 0 or more "e"s, then, any character followed by "cgi"
Although I agree with the previous suggestions of using the glob function instead of your own grep, your script should work as well.
I guess that your problem is due to a premature expansion of your regular expression: if you don't enclose the regexp in quotes it will be expanded by the shell before passing the arguments to the script:
Suppose that you have a directory like this:
$ ls -1 /tmp/test/ other.txt test10.txt test1.txt test2.txt test3.txt
If you name your script "find_files.pl" and you call it with:
$ perl find_files.pl test*.txt
then, the shell will try to expand test*.txt and will pass the result of this expansion to the script. If you don't want this, you must put single quotes around it and provide the script with a valid perl regular expression like in:
$ perl find_files.pl 'test.*\.txt' wildcard is test.*\.txt /tmp/test/test10.txt /tmp/test/test3.txt /tmp/test/test2.txt /tmp/test/test1.txt
citromatik
In reply to Re: Wildcard search in a directory
by citromatik
in thread Wildcard search in a directory
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |