summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--doc/coreutils.texi2
-rw-r--r--src/echo.c2
-rw-r--r--src/printf.c7
-rw-r--r--src/stat.c3
-rwxr-xr-xtests/misc/printf3
6 files changed, 18 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 35d141323..abf2466b6 100644
--- a/NEWS
+++ b/NEWS
@@ -43,6 +43,8 @@ GNU coreutils NEWS -*- outline -*-
with the invoked command failing with status 1. Likewise, nohup
fails with status 125 instead of 127.
+ echo and printf now interpret \e as the Escape character (0x1B).
+
** New features
env and printenv now accept the option --null (-0), as a means to
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 9b9f73bef..df7e9634e 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -10800,6 +10800,8 @@ alert (bell)
backspace
@item \c
produce no further output
+@item \e
+escape
@item \f
form feed
@item \n
diff --git a/src/echo.c b/src/echo.c
index 90b978646..65e8c80e4 100644
--- a/src/echo.c
+++ b/src/echo.c
@@ -70,6 +70,7 @@ If -e is in effect, the following sequences are recognized:\n\
"), stdout);
fputs (_("\
\\c produce no further output\n\
+ \\e escape\n\
\\f form feed\n\
\\n new line\n\
\\r carriage return\n\
@@ -203,6 +204,7 @@ just_echo:
case 'a': c = '\a'; break;
case 'b': c = '\b'; break;
case 'c': exit (EXIT_SUCCESS);
+ case 'e': c = '\x1B'; break;
case 'f': c = '\f'; break;
case 'n': c = '\n'; break;
case 'r': c = '\r'; break;
diff --git a/src/printf.c b/src/printf.c
index f6f86a573..540d7db3f 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -25,6 +25,7 @@
\a = alert (bell)
\b = backspace
\c = produce no further output
+ \e = escape
\f = form feed
\n = new line
\r = carriage return
@@ -108,6 +109,7 @@ FORMAT controls the output as in C printf. Interpreted sequences are:\n\
\\a alert (BEL)\n\
\\b backspace\n\
\\c produce no further output\n\
+ \\e escape\n\
\\f form feed\n\
"), stdout);
fputs (_("\
@@ -200,6 +202,9 @@ print_esc_char (char c)
case 'c': /* Cancel the rest of the output. */
exit (EXIT_SUCCESS);
break;
+ case 'e': /* Escape. */
+ putchar ('\x1B');
+ break;
case 'f': /* Form feed. */
putchar ('\f');
break;
@@ -256,7 +261,7 @@ print_esc (const char *escstart, bool octal_0)
esc_value = esc_value * 8 + octtobin (*p);
putchar (esc_value);
}
- else if (*p && strchr ("\"\\abcfnrtv", *p))
+ else if (*p && strchr ("\"\\abcefnrtv", *p))
print_esc_char (*p++);
else if (*p == 'u' || *p == 'U')
{
diff --git a/src/stat.c b/src/stat.c
index ae5491154..35f5d6647 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -723,6 +723,9 @@ print_esc_char (char c)
case 'b': /* Backspace. */
c ='\b';
break;
+ case 'e': /* Escape. */
+ c ='\x1B';
+ break;
case 'f': /* Form feed. */
c ='\f';
break;
diff --git a/tests/misc/printf b/tests/misc/printf
index e02a1328b..8961b4433 100755
--- a/tests/misc/printf
+++ b/tests/misc/printf
@@ -28,6 +28,9 @@ getlimits_
fail=0
+# Verify the 3 methods of specifying "Escape":
+test $("$prog" "\x1b\n\33\n\e\n" | uniq -u) && fail=1
+
# This would fail (by printing the `--') for printf in sh-utils
# and in coreutils 4.5.1.
"$prog" -- 'foo\n' > out || fail=1