On 03/11/15 14:57, Jim Meyering wrote:
> On Tue, Nov 3, 2015 at 5:53 AM, Pádraig Brady <[email protected]> wrote:
>> I noticed in the info docs that ls may change to "shell" quoting by default.
>>
>>   "You can specify the default value of the ‘--quoting-style’ option
>>    with the environment variable ‘QUOTING_STYLE’.  If that environment
>>    variable is not set, the default value is ‘literal’, but this
>>    default may change to ‘shell’ in a future version of this package."
>>
>> Given the new support for "shell-escape" quoting which provides
>> both a concise and unambiguous output, should we now consider
>> enabling that by default?
>>
>> $ touch '1 2' 3 $'4\r'
>> $ ls-old
>> 1 2  3  4?
>> $ ls-new
>> '1 2'  3  '4'$'\r'
> 
> Yes, please.
> Those question marks struck me as anachronistic 10 years ago.

Patch attached.

Note I've not changed it when piping as that's probably not wanted
and pretty much guaranteed to break scripts in the presence of
any names requiring quoting. I.E. anything like:

  ls -rt | while read file; process "$file"; done

cheers,
Pádraig
>From 24a6651a2fcca0ba9eeb199caf67f31b1841b762 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Tue, 3 Nov 2015 16:32:08 +0000
Subject: [PATCH] ls: default to --quoting=shell-escape for output to terminal

* src/ls.c (decode_switches): Set "shell-escape" if isatty().
* doc/coreutils.texi (ls invocation): Update the defaults description.
* NEWS: Mention the change in behavior.  It should not have
backwards compat issues, but mentioning here just in case.
---
 NEWS               | 3 +++
 doc/coreutils.texi | 4 ++--
 src/ls.c           | 1 +
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 38b4664..08cb138 100644
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   df now prefers sources towards the root of a device when
   eliding duplicate bind mounted entries.
 
+  ls now quotes file names unambiguously and appropriate for use in a shell,
+  when outputting to a terminal.
+
 ** Improvements
 
   All utilities now quote user supplied arguments in error strings,
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 8618a64..8034807 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -7704,8 +7704,8 @@ this"} in the default C locale.  This looks nicer on many displays.
 
 You can specify the default value of the @option{--quoting-style} option
 with the environment variable @env{QUOTING_STYLE}@.  If that environment
-variable is not set, the default value is @samp{literal}, but this
-default may change to @samp{shell} in a future version of this package.
+variable is not set, the default value is @samp{shell-escape} when the
+output is a terminal, and @samp{literal} otherwise.
 
 @item --show-control-chars
 @opindex --show-control-chars
diff --git a/src/ls.c b/src/ls.c
index 20eb07d..df4dc6b 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -1581,6 +1581,7 @@ decode_switches (int argc, char **argv)
       if (isatty (STDOUT_FILENO))
         {
           format = many_per_line;
+          set_quoting_style (NULL, shell_escape_quoting_style);
           /* See description of qmark_funny_chars, above.  */
           qmark_funny_chars = true;
         }
-- 
2.5.0

Reply via email to