Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu' -DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2 -DDEFAULT_PATH_VALUE='/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin' -DSTANDARD_UTILS_PATH='/usr/bin:/bin:/usr/sbin:/sbin' -DSYS_BASHRC='/etc/bash.bashrc' -DSYS_BASH_LOGOUT='/etc/bash.bash_logout' uname output: Linux fcku 3.8.4-1-ARCH #1 SMP PREEMPT Wed Mar 20 22:10:25 CET 2013 x86_64 GNU/Linux Machine Type: x86_64-unknown-linux-gnu
Bash Version: 4.2 Patch Level: 45 Release Status: release Description: Currently it seems to be impossible to e.g. print "-n" with the builtin echo witout any extra characters. Repeat-By: Invoke echo with the string "-n" being the string to be outputted. Expected output: "-n" Fix: The attached patch makes the builtin echo to interpret '--' as the end of options.
>From a30b02d03f54777bc0e59e2a0086249fde932308 Mon Sep 17 00:00:00 2001 From: Hemmo Nieminen <hemmo.niemi...@iki.fi> Date: Mon, 1 Apr 2013 14:59:26 +0300 Subject: [PATCH] Adding support for '--' in builtin echo's option parsing. A '--' can now be used to mark the end of echo's options that should be parsed. This makes it possible to e.g. print lines where the first argument matches some of echo's options (e.g. 'echo -- -e'). --- builtins/echo.def | 15 +++++++++++++-- doc/bash.1 | 7 +++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/builtins/echo.def b/builtins/echo.def index 62c6199..62e75c3 100644 --- a/builtins/echo.def +++ b/builtins/echo.def @@ -35,7 +35,7 @@ $PRODUCES echo.c $BUILTIN echo $FUNCTION echo_builtin $DEPENDS_ON V9_ECHO -$SHORT_DOC echo [-neE] [arg ...] +$SHORT_DOC echo [-neE] [--] [arg ...] Write arguments to the standard output. Display the ARGs on the standard output followed by a newline. @@ -45,6 +45,8 @@ Options: -e enable interpretation of the following backslash escapes -E explicitly suppress interpretation of backslash escapes +A '--' can be used to mark the end of options. + `echo' interprets the following backslash-escaped characters: \a alert (bell) \b backspace @@ -68,7 +70,7 @@ $END $BUILTIN echo $FUNCTION echo_builtin $DEPENDS_ON !V9_ECHO -$SHORT_DOC echo [-n] [arg ...] +$SHORT_DOC echo [-n] [--] [arg ...] Write arguments to the standard output. Display the ARGs on the standard output followed by a newline. @@ -76,6 +78,8 @@ Display the ARGs on the standard output followed by a newline. Options: -n do not append a newline +A '--' can be used to mark the end of options. + Exit Status: Returns success unless a write error occurs. $END @@ -122,6 +126,13 @@ echo_builtin (list) string should just be echoed. */ temp++; + if (temp[0] == '-' && temp[1] == '\0') + { + list = list->next; + break; + } + + for (i = 0; temp[i]; i++) { if (strchr (VALID_ECHO_OPTIONS, temp[i]) == 0) diff --git a/doc/bash.1 b/doc/bash.1 index 103d27e..4ca17d5 100644 --- a/doc/bash.1 +++ b/doc/bash.1 @@ -7325,7 +7325,7 @@ The return value is 0 unless a .I jobspec does not specify a valid job. .TP -\fBecho\fP [\fB\-neE\fP] [\fIarg\fP ...] +\fBecho\fP [\fB\-neE\fP] [\fB\-\-\fP] [\fIarg\fP ...] Output the \fIarg\fPs, separated by spaces, followed by a newline. The return status is always 0. If \fB\-n\fP is specified, the trailing newline is @@ -7336,9 +7336,8 @@ option disables the interpretation of these escape characters, even on systems where they are interpreted by default. The \fBxpg_echo\fP shell option may be used to dynamically determine whether or not \fBecho\fP expands these -escape characters by default. -.B echo -does not interpret \fB\-\-\fP to mean the end of options. +escape characters by default. \fB\-\-\fP can be used to mark the +end of options. .B echo interprets the following escape sequences: .RS -- 1.8.2