Note that the ls command isn't interpreting patterns in filenames at all - it never even sees them. Pattern expansion is done by the shell, which pre-expands patterns to lists of file names which match the pattern, and then passes the expanded list to whatever program is invoked.
The good news about this method is that it ensures consistency in pattern expansion, unlike with DOS which relies on each program implementing pattern expansion.
The bad news is that there are many different shell implementations, and so there is scope for some differences in how pattern expansion is done. Fortunately, most common shells implement patterns in broadly compatible ways.
Bash, which is
probably your shell if you are using a modern Linux distro (find out by typing "ps -p $$" in your shell), has several modes for pattern expansion, which you can switch between.
Basically, it uses glob expansion, where ? is a single character wildcard, * matches any string, and [chars] can be used to specify from a list of characters. There are some more options too. See the "Pathname Expansion" section of the bash manual page for details.
Regarding this specific case of
It's curious.
To find out what is happening, I'd recommand adding the -d option, which prevents ls from looking inside directories whicg are passed to it.
I cannot replicate the behaviour you describe - with ?? not expanding if it is followed by /etc:
Code:
matthew@chubby:~/tmp/testdir$ pwd
/home/matthew/tmp/testdir
matthew@chubby:~/tmp/testdir$ ls -d ?? /etc
ls: ??: No such file or directory
/etc/
matthew@chubby:~/tmp/testdir$ touch aa ab ac
matthew@chubby:~/tmp/testdir$ ls -d ??
aa ab ac
matthew@chubby:~/tmp/testdir$ ls -d ?? /etc
aa ab ac /etc/
...seems to work for me. If you have the failglob shopt set and ?? doesn't match any files, the ls won't be executed, so you might just see the error message, if there are no filenames with two characters in the current working directory.