2011-10-03, 13:48(+02), Andreas Schwab: > Stephane CHAZELAS <stephane_chaze...@yahoo.fr> writes: > >> The problem and confusion here comes from the fact that "\" is >> overloaded and used by two different pieces of software (bash >> and the system regex). > > That's nothing new. The backslash is widely used as a quote character > in several languages, which requires two levels of quoting if one of > these languages is embedded in another one. [...]
Yes, but in this case, contrary to zsh doesn't do two levels of quoting. Bash quoting means to escape the RE operators, and that's where the problem comes from. For it to work fully, bash would need to implement the full RE parsing to know where to put backslashes when characters are quoted. Bash turns: "." to \. before calling the regex(3) API '[.]' to \[\.\] (fine) ['.'] to [\.] (not fine) ['a]'] to [a\]] (not fine) (.)\1 to (.)1 (fine or not fine depending on how you want to look at it) (?i:test} to (?i:test) (assuming regex(3) are implemented with PCREs: fine or not fine depending on how you want to look at it). In zsh, it's simpler as quoting just quotes shell characters, it doesn't try to escape regexp operators. -- Stephane