bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] doc: improve the echo and printf help on escapes


From: Pádraig Brady
Subject: Re: [PATCH] doc: improve the echo and printf help on escapes
Date: Wed, 28 Oct 2009 12:06:15 +0000
User-agent: Thunderbird 2.0.0.6 (X11/20071008)

Eric Blake wrote:
> According to Jim Meyering on 10/28/2009 5:31 AM:
>>> * src/echo.c (usage): Likewise.
>>> Also mention the \xHH escape sequence.
> 
> While we're at it, bash's builtin echo supports \E as an escape for ascii
> ESC; do we want to add that as well, for consistency across GNU projects?

Great minds think alike :)
Note gcc, perl, bash, ksh and tcsh support \e
while POSIX, dash & python do not.

commit 983b46bfa497aef12680e4a732cf5556de96a053
Author: Pádraig Brady <address@hidden>
Date:   Tue Oct 27 10:04:34 2009 +0000

    echo, printf: interpret \e as the Escape character

    * src/printf.c (?): Output \x1B when \e encountered.
    * src/echo.c (?): Likewise.
    * doc/coreutils.texi (echo invocation): Add \e to the list.
    * NEWS: Mention the change in behaviour.

diff --git a/NEWS b/NEWS
index 315ae5f..87b5d11 100644
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,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

   md5sum --check now also accepts openssl-style checksums.
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index c54ffb8..f1a95f3 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -10796,6 +10796,8 @@ alert (bell)
 backspace
 @item \c
 produce no further output
address@hidden \e
+escape
 @item \f
 form feed
 @item \n
diff --git a/src/echo.c b/src/echo.c
index 90b9786..65e8c80 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 f6f86a5..540d7db 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')
     {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]