aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-04-29 08:54:45 -0700
committerRob Landley <rob@landley.net>2019-04-30 17:05:31 -0500
commite425ab040b5315d94d59aa4448dc578daf894979 (patch)
treed9ff805c3a2755f59cd5d2dfea0362f134eb2865
parent07a716b167ef6b21f82c86b026dc0f8fdd385c6f (diff)
downloadtoybox-e425ab040b5315d94d59aa4448dc578daf894979.tar.gz
echo: add -E.
POSIX finally gave us a way to use echo in a portable way despite differences of opinion about whether to default interpretation of escape sequences to on or off: -e enables and -E disables (as already implemented by busybox and coreutils). http://austingroupbugs.net/view.php?id=1222
-rwxr-xr-xtests/echo.test3
-rw-r--r--toys/posix/echo.c5
2 files changed, 6 insertions, 2 deletions
diff --git a/tests/echo.test b/tests/echo.test
index e2035561..fa53559a 100755
--- a/tests/echo.test
+++ b/tests/echo.test
@@ -34,3 +34,6 @@ testcmd "-e hexadecimal values" \
"S4 0 XYZ ?\n" "" ""
testcmd "-e \p" "-e '\\p'" "\\p\n" "" ""
+
+# http://austingroupbugs.net/view.php?id=1222 added -E
+testcmd "-En" "-En 'one\ntwo'" 'one\\ntwo' "" ""
diff --git a/toys/posix/echo.c b/toys/posix/echo.c
index 63eb1981..11a68a9b 100644
--- a/toys/posix/echo.c
+++ b/toys/posix/echo.c
@@ -9,13 +9,13 @@
* We also honor -- to _stop_ option parsing (bash doesn't, we go with
* consistency over compatibility here).
-USE_ECHO(NEWTOY(echo, "^?en", TOYFLAG_BIN))
+USE_ECHO(NEWTOY(echo, "^?Een", TOYFLAG_BIN))
config ECHO
bool "echo"
default y
help
- usage: echo [-ne] [args...]
+ usage: echo [-neE] [args...]
Write each argument to stdout, with one space between each, followed
by a newline.
@@ -33,6 +33,7 @@ config ECHO
\t Horizontal tab
\v Vertical tab
\xHH Hexadecimal values (1 to 2 digits)
+ -E Print escape sequences literally (default)
*/
#define FOR_echo