[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bash 2.05b 'echo' incompatibility with POSIX-2004 and SUSv2
From: |
Paul Eggert |
Subject: |
bash 2.05b 'echo' incompatibility with POSIX-2004 and SUSv2 |
Date: |
Wed, 12 May 2004 18:24:26 -0700 |
User-agent: |
Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (usg-unix-v) |
Configuration Information [Automatically generated, do not change]:
Machine: sparc
OS: solaris2.9
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='sparc'
-DCONF_OSTYPE='solaris2.9' -DCONF_MACHTYPE='sparc-sun-solaris2.9'
-DCONF_VENDOR='sun' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -g
-O2 -Wall -W -Wno-sign-compare -Wpointer-arith -Wstrict-prototypes
-Wmissing-prototypes -Wmissing-noreturn -Wmissing-format-attribute
uname output: SunOS pete.twinsun.com 5.9 Generic_112233-12 sun4u sparc
SUNW,UltraAX-i2
Machine Type: sparc-sun-solaris2.9
Bash Version: 2.05b
Patch Level: 0
Release Status: release
Description:
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. I'll send a similar patch to bug-coreutils so
that its "echo" is also fixed.
===================================================================
RCS file: doc/bashref.texi,v
retrieving revision 2.5.2.1
retrieving revision 2.5.2.2
diff -pu -r2.5.2.1 -r2.5.2.2
--- doc/bashref.texi 2003/09/26 20:24:50 2.5.2.1
+++ doc/bashref.texi 2004/05/13 01:07:41 2.5.2.2
@@ -3518,7 +3518,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
@@ -5607,6 +5608,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,
+@code{echo -ne hello} outputs @samp{-ne hello} instead of plain
+@samp{hello}.
+
+@item
The @code{trap} builtin displays signal names without the leading
@code{SIG}.
===================================================================
RCS file: builtins/echo.def,v
retrieving revision 2.5.2.0
retrieving revision 2.5.2.1
diff -pu -r2.5.2.0 -r2.5.2.1
--- builtins/echo.def 2002/03/19 15:45:28 2.5.2.0
+++ builtins/echo.def 2004/05/13 01:07:41 2.5.2.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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bash 2.05b 'echo' incompatibility with POSIX-2004 and SUSv2,
Paul Eggert <=