Question

as the document describes,[set] in Bash can match any character in set,

in the following , I hava 3 dirs called a,b,c in current directory:


$ ls
a b c

$ ls [abd] # just as expected,show dirs a and b
a:

b:

$ ls [bd] # expecting show dir b but noting matched

$ ls [ad] # expecting show dir a but noting matched

can someone explain this to me?thanks!

Was it helpful?

Solution

This is correct behavior.

ls [bd]

Prints files inside the directory b and that is empty.

To test further you can do:

touch b/foo
ls [bd]

Which will give output

foo

PS: However in your first command when you do ls [abc] there are more than one matching directories in current path a and b hence you get the output as shown in in your question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top