Joerg Schilling <joerg.schill...@fokus.fraunhofer.de> wrote, on 12 Apr 2018:
>
> It seems that we need to define how quoting works in a real shell 
> implementation. 
> 
> If we require the strings to be in the form \c\h\a\r in case of a quoted 
> string 
> at that specific part of the shell, we may explain how quoting works for 
> "case"
> statements.
> 
> Maybe, I should again mention history:
> 
>       -       fmnatch() has been introduced with issue 4 (1995). It does not
>               seem to be related to a historic UNIX. Since the oldest known
>               implementation is from IBM, fnmatch() may have been introduced
>               by AIX.

It was first standardised in POSIX.2-1992 and was invented by the developers
of that standard.

[...] 
> Now let us check the behavior of various shells with the following script:
> 

[...]
> As we can see:
> 
> -     The Bourne Shell interprets backshlash escapes
>       inside character classes.
> 
> -     All other (relevant) shells behave identically
>       except ksh88 and ksh93
> 
> -     ksh88 does not honor backslashes inside a
>       character class. Since ksh93 changes this back to the
>       original Bourne Shell behavior, I would call it a bug.
> 
> -     ksh93 interprets ["a-c"] different from all
>       other shells, but again interprets backshlash escapes
>       inside character classes.
> 
>       I remember that I received a report from someone (maybe
>       Martijn Dekker or Thorsten Glaser) that ksh93 has problems
>       with " inside some expressions.
> 
>       I would call the single deviation seen in ksh93 a bug.
>       The reason for this other behavior does not seem to be related
>       to pattern matching but to the way quote removal has been
>       implemented.
> 
> Conclusion:
> 
> Since the behavior of fnmatch() is currently not able to match the behavior
> of the shell matcher, I propose to add a new flag for fnmatch() to switch
> it into the shell mode that honors backslashes inside character sets.

You are conflating two different type of backslash escape.

The shell should honour backslash when used as shell quoting, regardless
of whether it is inside a bracket expression, but should not treat a
backslash in a bracket expression *that is part of the pattern* (i.e. not
shell quoting) as special.

For example:

[\"]     the backslash quotes the "

["a\-c"] the backslash is not special and should be treated literally

If you want fnmatch() to be able to work like the shell you would need
the new flag to turn on all shell quoting (i.e. backslash, double-quotes
and single-quotes), not just backslash.

-- 
Geoff Clare <g.cl...@opengroup.org>
The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England

Reply via email to