From OpenBSD: 2009-02-07 15:03 kili * c_ksh.c (1.33): Ensure that *wp isn't NULL. ok otto@ 2009-02-07 08:24 guenther * c_ksh.c (1.32), ksh.1 (1.124), sh.1 (1.78): Make built-in echo behave according to POSIX when set -o posix is in effect: the only option is -n, and only one of those is parsed. diff from Ingo Schwarze ok otto@ kili@; manpage changes ok jmc@ Index: pdksh-5.2.14/c_ksh.c =================================================================== --- pdksh-5.2.14.orig/c_ksh.c 2009-09-19 11:22:34.000000000 +0200 +++ pdksh-5.2.14/c_ksh.c 2009-09-19 12:13:54.000000000 +0200 @@ -247,23 +247,30 @@ * by default. */ wp += 1; - while ((s = *wp) && *s == '-' && s[1]) { - while (*++s) - if (*s == 'n') - nflags &= ~PO_NL; - else if (*s == 'e') - nflags |= PO_EXPAND; - else if (*s == 'E') - nflags &= ~PO_EXPAND; - else - /* bad option: don't use nflags, print - * argument - */ + if (Flag(FPOSIX)) { + if (*wp && strcmp(*wp, "-n") == 0) { + flags &= ~PO_NL; + wp++; + } + } else { + while ((s = *wp) && *s == '-' && s[1]) { + while (*++s) + if (*s == 'n') + nflags &= ~PO_NL; + else if (*s == 'e') + nflags |= PO_EXPAND; + else if (*s == 'E') + nflags &= ~PO_EXPAND; + else + /* bad option: don't use + * nflags, print argument + */ + break; + if (*s) break; - if (*s) - break; - wp++; - flags = nflags; + wp++; + flags = nflags; + } } } else { int optc; Index: pdksh-5.2.14/ksh.Man =================================================================== --- pdksh-5.2.14.orig/ksh.Man 2009-09-19 11:22:34.000000000 +0200 +++ pdksh-5.2.14/ksh.Man 2009-09-19 12:13:54.000000000 +0200 @@ -1521,6 +1521,13 @@ In future, a new option (\fB\-v\fP perhaps) will be added to distinguish the two behaviours. .IP \ \ \(bu +\fBecho\fP +options. +In POSIX mode, \fB\-e\fP and \fB\-E\fP +are not treated as options, but printed like other arguments; +in non-POSIX mode, these options control the interpretation +of backslash sequences. +.IP \ \ \(bu \fBfg\fP exit status: in posix mode, the exit status is 0 if no errors occur; in non-posix mode, the exit status is that of the last foregrounded job. .IP \ \ \(bu @@ -1780,6 +1787,9 @@ \fB\-n\fP suppresses the trailing newline, \fB\-e\fP enables backslash interpretation (a no-op, since this is normally done), and \fB\-E\fP which suppresses backslash interpretation. +If the \fIposix\fP +option is set, only the first argument is treated as an option, and only +if it is exactly \fB-n\fP. .\"}}} .\"{{{ eval command ... .IP "\fBeval\fP \fIcommand ...\fP" Index: pdksh-5.2.14/tests/debian-115.t =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ pdksh-5.2.14/tests/debian-115.t 2009-09-19 12:18:11.000000000 +0200 @@ -0,0 +1,38 @@ +name: debian-115-1 +description: + Check if echo does not accept -e in posix mode +stdin: + set -o posix + echo -e test +expected-stdout: + -e test +--- +name: debian-115-2 +description: + Check if echo accepts -e in non-posix mode +stdin: + set +o posix + echo -e test +expected-stdout: + test +--- +name: debian-115-3 +description: + Check if echo accepts -n in posix mode +stdin: + set -o posix + echo -n test + echo " OK" +expected-stdout: + test OK +--- +name: debian-115-4 +description: + Check if echo accepts -n in non-posix mode +stdin: + set +o posix + echo -n test + echo " OK" +expected-stdout: + test OK +---