diff options
author | Pádraig Brady <P@draigBrady.com> | 2009-10-27 10:04:34 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2009-10-28 16:37:07 +0000 |
commit | 2904d675a49cdd7cb2372f50592a6823106aa0f7 (patch) | |
tree | 4ec374f8d26b4f1ac3e7454233ab0adc732cc2b8 /src/printf.c | |
parent | 54491d275184428be6e28e3f22f04859b7288105 (diff) | |
download | coreutils-2904d675a49cdd7cb2372f50592a6823106aa0f7.tar.xz |
echo, printf: interpret \e as the Escape character
Match gcc, perl, bash, ksh, tcsh, ... in supporting \e.
* src/printf.c (print_escape_char): Output \x1B when \e encountered.
* src/echo.c (main): Likewise.
* src/stat.c (print_escape_char): Likewise.
* doc/coreutils.texi (echo invocation): Add \e to the list.
* tests/misc/printf: Verify that \e outputs \x1B.
* NEWS: Mention the change in behaviour.
Diffstat (limited to 'src/printf.c')
-rw-r--r-- | src/printf.c | 7 |
1 files changed, 6 insertions, 1 deletions
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') { |