On Mon, May 04, 2009 at 12:34:19AM +0800, jida...@jidanni.org wrote: > Maybe mention in the man page at > [...] Matches any one of the enclosed characters... > that one will need to backslash at least any spaces used inside it: > $ ls [^ ] > ls: cannot access [^: No such file or directory > ls: cannot access ]: No such file or directory
This isn't due to the behavior of [...] but rather due to word-splitting by the command parser before [...] is handled at all. The unquoted space character causes the word splitting, which is why ls is receiving two arguments. As you can see, the [ and ] are being passed as literal characters, because each of the two words fails to contain both [ and ] to make a whole character-range glob. > $ ls [^\ ] > a The interaction between shell features (in this case, character-range globbing and word splitting) can sometimes be awkward. The intuitive way to handle this would have been "[^ ]" but then you lose the special significance of the [ and ], so that obviously fails. Putting the quotes inside -- [^" "] -- works. But the backslash approach you used is probably the clearest way to write it.