Subject: Re: bug#33113: incorrect and inconsistent quoting in ls output

From: Vincent Lefevre <[email-masked]>
Date: Mon, 22 Oct 2018 10:44:57 +0200

On 2018-10-22 01:21:40 -0700, Paul Eggert wrote:
> Vincent Lefevre wrote:
> > I get the following with ls (GNU coreutils) 8.30.
> > 
> > zira% touch a=b a=b\&c
> > zira% ls a=b*
> > 'a=b'  'a=b&c'
> > zira% ls -b a=b*
> > a=b  a=b&c
> > zira% ls -F a=b*
> > 'a=b'  'a=b&c'
> > zira% ls -bF a=b*
> > a\=b  a\=b&c
> > 
> > AFAIK, the = character is not a shell metacharacter (except with zsh
> > but only in the first position), thus does not need to be quoted.

Actually it seems that the meaning of "metacharacter" is ambiguous.
In bash, & is regarded as a metacharacter:

  metacharacter
      A  character that, when unquoted, separates words.  One of the
      following:
      |  & ; ( ) < > space tab newline

> '=' is a shell metacharacter after 'set -k' in Bash.

It's a special character, but not a metacharacter (see above).
But then I agree on the need for quoting, if particular shells
are taking into account.

> > Moreover, while & is not a metacharacter, it is a special character
> > that should be quoted for practical reasons.
> 
> As far as I can see '&' is being quoted correctly in the above examples.

Not with "ls -bF": the quoting in a\=b&c is inconsistent.
Just like =, & should be quoted. Or = shouldn't be quoted
(see below).

> -b means to quote for C strings, not for the shell.

Hmm, yes... The issue here is that -b was actually changing the
quoting style, hence my confusion on this point. That's a bug in
the ls man page, which does not say so:

       -b, --escape
              print C-style escapes for nongraphic characters

The info manual is OK:

‘-b’
‘--escape’
‘--quoting-style=escape’
     Quote nongraphic characters in file names using alphabetic and
     octal backslash sequences like those used in C.

> If you want to quote for the shell, try
> --quoting-style='shell-escape'.

That's already the default. Actually, the confusion comes from the
ls man page.

On the behavior, there's still the issue concerning = and &.

-- 
Vincent Lefèvre <[email-masked]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)