I'm making a bash shell script to find files with the star character in their name (*). My test directory has two files that match this criterion:
./File.With*In.It
./File.With*In.It copy
When I run the following command via Terminal on OS X, I get the aforementioned list above as my result:
find . -name '*\**'
But, in my shell script, I have the following line of code:
listOfStars=`find . -name '*\**'`
printf "%s\n" ${listOfStars}
And, if I execute the script, the result I get includes every file in the directory:
.
./File.With"In.It
./File.With"In.It copy
./File.With*In.It
./File.With*In.It copy
./File.With.In.It.
./File.With.In.It. copy.
./File.With:In.It
./File.With:In.It copy
./File.With<In.It
./File.With<In.It copy
./File.With>In.It
./File.With>In.It copy
./File.With?In.It
./File.With?In.It copy
./File.With\In.It
./File.With\In.It copy
./File.With|In.It
./File.With|In.It copy
On further testing, if I execute those two lines of code right in the Terminal, I also get the same results; every file in the directory matches the search. The obvious conclusion is that find
- in the way I am using it - is giving me a different result when it's assigned to my variable than when I run the command all on its own.
What can I do to get find
to behave in my variable the same way it does when summoned by itself? Or is there a more prudent approach to getting a list of files with star (*
) in their names and assigning it to a variable in my bash shell script?