Reputation: 763
I was playing around with some bash features and as I tried echo-ing some output, I noticed, that
echo what about in some more complex example ?
results in
what about in some more complex example \
I know that escaping the question mark or the whole line with quotes resolves the problem, but I am curious of why is it happening.
So my 2 questions are:
type cd
Upvotes: 3
Views: 3970
Reputation: 50785
In that context it functions as a glob pattern. If there are files with one-character names in the current working directory, the shell expands an unquoted question mark to their names.
$ echo ? \? '?' "?"
? ? ? ?
$ touch a b c
$ echo ? \? '?' "?"
a b c ? ? ?
Similarly, ??
is expanded to two-character filenames, ??*
to filenames longer than one character, and ??[ab]
to three-character filenames ending with an a or a b, etc.
See Filename Expansion for further information.
Upvotes: 5