From e897dfd023dad6b9173ad457fc9d9110f2403a5f Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?=
Date: Thu, 30 Jul 2026 21:48:22 +0100
Subject: [PATCH] basename: quote problematic names on tty
* doc/coreutils.texi (basename invocation): Mention $QUOTING_STYLE
is significant.
* src/basename.c (perform_basename, main): Quote output when
appropriate.
* tests/misc/basename.pl: Add a test case.
* NEWS: Mention the improvement.
---
NEWS | 2 +-
doc/coreutils.texi | 5 +++++
src/basename.c | 17 ++++++++++++++++-
tests/misc/basename.pl | 10 ++++++++++
4 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index 7d17ff5e63..0667f4fddc 100644
--- a/NEWS
+++ b/NEWS
@@ -84,7 +84,7 @@ GNU coreutils NEWS -*- outline -*-
'install -C' will now avoid updating file metadata when the destination
already has the appropriate ownership and permissions.
- 'realpath' now quotes output in shell-escape style when
+ 'basename' and 'realpath' now quote output in shell-escape style when
standard output is a terminal. The QUOTING_STYLE environment variable
can be used to adjust or disable the quoting.
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index c17fda0f9b..d9b6a8761f 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -14193,6 +14193,11 @@ This option implies the @option{-a} option.
@end table
+When standard output is a terminal, output is quoted using the
+@samp{shell-escape} style. The environment variable
+@env{QUOTING_STYLE} specifies the quoting style. Valid quoting styles are:
+@quotingStyles
+
@exitstatus
Examples:
diff --git a/src/basename.c b/src/basename.c
index 96bbb71c52..4fc0864355 100644
--- a/src/basename.c
+++ b/src/basename.c
@@ -19,6 +19,7 @@
#include