* src/stat.c: Use %Qn rather than a bare %n by default,
so output is maintained on a single line for parsing.
---
doc/coreutils.texi | 4 ++--
src/stat.c | 8 ++++----
tests/stat/stat-fmt.sh | 8 ++++++++
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 5ab056ce1..33c7f1959 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -12539,13 +12539,13 @@ also identifies the items printed (in fuller form) in
the default format.
The format string would include another @samp{%C} at the end with an
active SELinux security context.
@example
-$ stat --format="%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o" ...
+$ stat --format="%Qn %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o" ...
$ stat --terse ...
@end example
The same illustrating terse output in @option{--file-system} mode:
@example
-$ stat -f --format="%n %i %l %t %s %S %b %f %a %c %d" ...
+$ stat -f --format="%Qn %i %l %t %s %S %b %f %a %c %d" ...
$ stat -f --terse ...
@end example
@end table
diff --git a/src/stat.c b/src/stat.c
index 3995acdfe..048c061be 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -179,10 +179,10 @@ static char const digits[] = "0123456789";
static char const printf_flags[] = "'-+ #0I";
/* Formats for the --terse option. */
-static char const fmt_terse_fs[] = "%n %i %l %t %s %S %b %f %a %c %d\n";
-static char const fmt_terse_regular[] = "%n %s %b %f %u %g %D %i %h %t %T"
+static char const fmt_terse_fs[] = "%Qn %i %l %t %s %S %b %f %a %c %d\n";
+static char const fmt_terse_regular[] = "%Qn %s %b %f %u %g %D %i %h %t %T"
" %X %Y %Z %W %o\n";
-static char const fmt_terse_selinux[] = "%n %s %b %f %u %g %D %i %h %t %T"
+static char const fmt_terse_selinux[] = "%Qn %s %b %f %u %g %D %i %h %t %T"
" %X %Y %Z %W %o %C\n";
#define PROGRAM_NAME "stat"
@@ -1687,7 +1687,7 @@ default_format (bool fs, bool terse, bool device)
{
/* TRANSLATORS: This string uses format specifiers from
'stat --help' with --file-system, and NOT from printf. */
- format = xstrdup (_(" File: \"%n\"\n"
+ format = xstrdup (_(" File: \"%Qn\"\n"
" ID: %-8i Namelen: %-7l Type: %T\n"
"Block size: %-10s Fundamental block size: %S\n"
"Blocks: Total: %-10b Free: %-10f Available:
%a\n"
diff --git a/tests/stat/stat-fmt.sh b/tests/stat/stat-fmt.sh
index 7e62f015c..beb87db50 100755
--- a/tests/stat/stat-fmt.sh
+++ b/tests/stat/stat-fmt.sh
@@ -68,6 +68,14 @@ cat <<\EOF >exp
File: 'a'$'\n\n''b'$'\n''c'
EOF
compare exp out || fail=1
+# likewise with --terse
+stat --terse "$fname" | cut -d ' ' -f1 > out || fail=1
+cat <<\EOF >exp
+'a'$'\n\n''b'$'\n''c'
+EOF
+compare exp out || fail=1
+stat -f --terse "$fname" | cut -d ' ' -f1 > out || fail=1
+compare exp out || fail=1
# Check the behavior with invalid values of QUOTING_STYLE.
for style in '' 'abcdef'; do
--
2.54.0