bug-bash
[Top][All Lists]
Advanced

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

bash 3.0 'echo' incompatibility with POSIX-2004 and SUSv2


From: Paul Eggert
Subject: bash 3.0 'echo' incompatibility with POSIX-2004 and SUSv2
Date: Sun, 08 Aug 2004 22:48:26 -0700

Configuration Information [Automatically generated, do not change]:
Machine: sparc
OS: solaris2.8
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='sparc' 
-DCONF_OSTYPE='solaris2.8' -DCONF_MACHTYPE='sparc-sun-solaris2.8' 
-DCONF_VENDOR='sun' -DLOCALEDIR='/opt/reb/share/locale' -DPACKAGE='bash' 
-DSHELL  -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib  -I/opt/reb/include -g 
-O2 -Wall -W -Wno-sign-compare -Wpointer-arith -Wstrict-prototypes 
-Wmissing-prototypes -Wmissing-noreturn -Wmissing-format-attribute
uname output: SunOS sic.twinsun.com 5.8 Generic_117350-05 sun4u sparc 
SUNW,UltraSPARC-IIi-Engine
Machine Type: sparc-sun-solaris2.8

Bash Version: 3.0
Patch Level: 0
Release Status: release

Description:
        (This is a 3.0-based followup to a May bug report
        <http://lists.gnu.org/archive/html/bug-bash/2004-05/msg00163.html>
        that I didn't get a response to.  On the theory that bug-bash
        is swamped by spam, I'm resending it, this time with a patch
        against 3.0.)

        (GNU coreutils "echo" was fixed in May.)


        POSIX says that the command "echo -e" must output the string "-e",
        but Bash's builtin "echo" command outputs nothing, even in
        POSIX-conforming mode.  Similarly, SUSv2 says that "echo -n"
        must output "-n", but Bash's "echo" outputs nothing, even
        when the xpg_echo option is on and POSIX-conforming mode is in effect.

        References:

        POSIX-2004 spec for 'echo':
        http://www.opengroup.org/onlinepubs/009695399/utilities/echo.html

        SUSv2 spec for 'echo':
        http://www.opengroup.org/onlinepubs/007908799/xcu/echo.html

Repeat-By:

        $ bash --posix
        1-red $ echo -e foo
        foo
        2-red $ shopt -s xpg_echo
        3-red $ echo -n foo
        foo4-red $ 

Fix:

The following patch affects Bash's behavior only when in
POSIX-conforming mode.

===================================================================
RCS file: doc/bashref.texi,v
retrieving revision 3.0
retrieving revision 3.0.0.1
diff -pu -r3.0 -r3.0.0.1
--- doc/bashref.texi    2004/06/26 18:26:07     3.0
+++ doc/bashref.texi    2004/08/09 04:04:53     3.0.0.1
@@ -3727,7 +3727,8 @@ This option is enabled by default.
 
 @item xpg_echo
 If set, the @code{echo} builtin expands backslash-escape sequences
-by default.
+by default, and outputs arguments like @option{-n} instead of treating
+them as options.
 
 @end table
 
@@ -5947,6 +5948,13 @@ The @code{export} and @code{readonly} bu
 output in the format required by @sc{posix} 1003.2.
 
 @item
+The @code{echo} command outputs option-like arguments instead of
+treating them as options if the @code{xpg_echo} shell option is on or
+if @code{echo}'s first argument is not @samp{-n}.  For example,
address@hidden -ne hello} outputs @samp{-ne hello} instead of plain
address@hidden
+
address@hidden
 The @code{trap} builtin displays signal names without the leading
 @code{SIG}.
 
===================================================================
RCS file: builtins/echo.def,v
retrieving revision 3.0
retrieving revision 3.0.0.1
diff -pu -r3.0 -r3.0.0.1
--- builtins/echo.def   2004/06/28 18:27:40     3.0
+++ builtins/echo.def   2004/08/09 03:53:50     3.0.0.1
@@ -31,6 +31,8 @@ $PRODUCES echo.c
 #include <stdio.h>
 #include "../shell.h"
 
+extern int posixly_correct;
+
 $BUILTIN echo
 $FUNCTION echo_builtin
 $DEPENDS_ON V9_ECHO
@@ -91,6 +93,11 @@ echo_builtin (list)
   do_v9 = xpg_echo;
   display_return = 1;
 
+  if (posixly_correct
+      && (xpg_echo
+         || !(list && (temp = list->word->word) && strcmp (temp, "-n") == 0)))
+    goto just_echo;
+
   for (; list && (temp = list->word->word) && *temp == '-'; list = list->next)
     {
       /* If it appears that we are handling options, then make sure that




reply via email to

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