[PATCH 2/6] printf: Support \e in "echo" and "printf" builtins.

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

 



From: Adam Borowski <kilobyte@xxxxxxxxxx>

dash's builtin version of printf doesn't support '\e' (escape), and literaly
outputs the 2 characters as-is. As is well known, this sequence is useful,
for example, when outputting ANSI escape sequences.

While it seems that POSIX does not require that printf support '\e',
it is still worth implementing '\e' support, as a way to make the environment
more consistent and avoid this small issue when porting scripts from certain
other systems or when migrating from bash to dash.

Signed-off-by: Adam Borowski <kilobyte@xxxxxxxxxx>
[reworded the patch description]
Signed-off-by: Andrej Shadura <andrew.shadura@xxxxxxxxxxxxxxx>
Bug-Debian: http://bugs.debian.org/816295
---
 src/bltin/printf.c | 1 +
 src/dash.1         | 4 ++++
 2 files changed, 5 insertions(+)

diff --git a/src/bltin/printf.c b/src/bltin/printf.c
index 7785735..9b878da 100644
--- a/src/bltin/printf.c
+++ b/src/bltin/printf.c
@@ -340,6 +340,7 @@ conv_escape(char *str, int *conv_ch)
 	case '\\':	value = '\\';	break;	/* backslash */
 	case 'a':	value = '\a';	break;	/* alert */
 	case 'b':	value = '\b';	break;	/* backspace */
+	case 'e':	value = '\e';	break;  /* escape */
 	case 'f':	value = '\f';	break;	/* form-feed */
 	case 'n':	value = '\n';	break;	/* newline */
 	case 'r':	value = '\r';	break;	/* carriage-return */
diff --git a/src/dash.1 b/src/dash.1
index 32f6ac0..b286f79 100644
--- a/src/dash.1
+++ b/src/dash.1
@@ -1201,6 +1201,8 @@ Subsequent output is suppressed.  This is normally used at the end of the
 last argument to suppress the trailing newline that
 .Ic echo
 would otherwise output.
+.It Li \ee
+Outputs an escape character (ESC).
 .It Li \ef
 Output a form feed.
 .It Li \en
@@ -1570,6 +1572,8 @@ The characters and their meanings are as follows:
 Write a \*[Lt]bell\*[Gt] character.
 .It Cm \eb
 Write a \*[Lt]backspace\*[Gt] character.
+.It Cm \ee
+Write an \*[Lt]escape\*[Gt] (ESC) character.
 .It Cm \ef
 Write a \*[Lt]form-feed\*[Gt] character.
 .It Cm \en
-- 
2.17.1




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux