bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mention what characters need to be escaped inside [...]


From: Greg Wooledge
Subject: Re: mention what characters need to be escaped inside [...]
Date: Mon, 4 May 2009 08:37:44 -0400
User-agent: Mutt/1.4.2.2i

On Mon, May 04, 2009 at 12:34:19AM +0800, address@hidden 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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]