Expanding to nothing

You may also have noticed with some experimentation with globs that if the pattern does not match anything, it expands to itself, unchanged:

$ printf '%s\n' c*
c*

Because none of our test files start with c, the glob is unexpanded and unchanged. This may seem strange; surely it would be better if the pattern expanded to nothing at all? It makes more sense when you consider the behavior of many classic Unix commands; if there are no arguments, they default to assuming input is coming from standard input. For example:

$ cat -- c*
cat: 'c*': No such file or directory

Because the pattern here did not expand, cat saw the c* argument, found the file named c* did not exist, and reported that to us, with an error message that ...

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.