As per my understanding, a glob wildcard is interpreted by the shell, which then runs the given command for each matching filename. Suppose I have files:
abc1, abc2, and abc3 in my current directory. Then, for example,
echo abc* will echo once for each filename starting with 'abc'.
However, if I run
grep 'foo' abc*, I imagine this should run:
grep 'foo' abc1 grep 'foo' abc2 grep 'foo' abc3
Which means i should get the following output (assuming all files contain one line that says 'foo'):
foo foo foo
However, instead I get:
abc1:foo abc2:foo abc3:foo
So I figure there are 2 possible explanations for this. First, is somehow grep can detect that it was used with a glob expressions and responds by outputting the filenames before the matches. Second, since you can pass multiple files to grep, the shell actually runs only 1 command:
grep 'foo' abc1 abc2 abc3
However, this only works because grep accepts multiple files at the end. It is possible that another command would only allow 1 file to be passed in. So if you wanted to run the command for multiple files matching the glob, it wouldn't work if globbing worked via the second method described above.
Anyways, can someone shed some light on this?