Why do the following two codes work as expected:
ls -d .[!.]?*
echo [D]*
But the following 2 don't:
ls -d [.][!.]?*
echo [D]
In the first command, I get an error:
ls: cannot access [.][!.]*: No such file or directory
When I am trying to get the same listing ls -d .[!.]?*
. And for the second, the output is:
[D]
When I'm expecting an error proclamation along the lines of No such file or directory
. What am I missing? What exactly makes an expression a wildcard, if those wildcard elements shown in the second set of examples above don't cut it?
Clarification (Also in comments):
The wildcard [D]*
doesn't only output D
, it also outputs Desktop
, Downloads
... etc. However, I also tried echo [D]
when I had a file named D and when I didn't. The output worked when the file D
was there, but I also got the output [D]
when it wasn't. I don't get why. Why did the presence of the file in the directory change the expression [D] from being a wild card to not?
D
in that directory?D
," when no file by the name exists at the time.D
" was an error proclamation along the lines ofNo such file or directory
.D
(especially when added a comment asserting you did) when you got behavior indicating you didn't (because you actually didn't at the time). You need to make sure that the conditions you describe and the output you list correspond to a single state of the system. If the conditions change, you need to provide an update explaining both the new conditions and new output.