summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2009-02-07 07:24:38 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2009-02-07 07:24:38 +0000
commit91d7c4b1e8e19265e830892187ee5e1792850a00 (patch)
treed83e4318c83470f1dca183a54eda4df9ec899bde
parentcd505e09aae6eed8cd553387a9b220f845cc0c45 (diff)
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@
-rw-r--r--bin/ksh/c_ksh.c41
-rw-r--r--bin/ksh/ksh.118
-rw-r--r--bin/ksh/sh.118
3 files changed, 56 insertions, 21 deletions
diff --git a/bin/ksh/c_ksh.c b/bin/ksh/c_ksh.c
index 080bb624acf..d2869225b53 100644
--- a/bin/ksh/c_ksh.c
+++ b/bin/ksh/c_ksh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: c_ksh.c,v 1.31 2008/05/17 23:31:52 sobrado Exp $ */
+/* $OpenBSD: c_ksh.c,v 1.32 2009/02/07 07:24:37 guenther Exp $ */
/*
* built-in Korn commands: c_*
@@ -228,23 +228,30 @@ c_print(char **wp)
* 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 (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;
diff --git a/bin/ksh/ksh.1 b/bin/ksh/ksh.1
index a25235e9e19..b0b6bd384b7 100644
--- a/bin/ksh/ksh.1
+++ b/bin/ksh/ksh.1
@@ -1,8 +1,8 @@
-.\" $OpenBSD: ksh.1,v 1.123 2009/01/29 23:27:26 jaredy Exp $
+.\" $OpenBSD: ksh.1,v 1.124 2009/02/07 07:24:37 guenther Exp $
.\"
.\" Public Domain
.\"
-.Dd $Mdocdate: January 29 2009 $
+.Dd $Mdocdate: February 7 2009 $
.Dt KSH 1
.Os
.Sh NAME
@@ -2500,6 +2500,16 @@ In the future, a new option
.Pq Fl v No perhaps
will be added to distinguish the two behaviours.
.It
+.Ic echo
+options.
+In POSIX mode,
+.Fl e
+and
+.Fl E
+will not be treated as options, but printed like other arguments;
+in non-POSIX mode, these options control the interpretation
+of backslash sequences.
+.It
.Ic fg
exit status.
In POSIX mode, the exit status is 0 if no errors occur;
@@ -3030,6 +3040,10 @@ option suppresses the trailing newline,
enables backslash interpretation (a no-op, since this is normally done), and
.Fl E
suppresses backslash interpretation.
+If the
+.Ic posix
+option is set, only the first argument is treated as an option, and only
+if it is exactly ``-n''.
.Pp
.It Ic eval Ar command ...
The arguments are concatenated (with spaces between them) to form a single
diff --git a/bin/ksh/sh.1 b/bin/ksh/sh.1
index 95ab08d9d09..232cf13061e 100644
--- a/bin/ksh/sh.1
+++ b/bin/ksh/sh.1
@@ -1,8 +1,8 @@
-.\" $OpenBSD: sh.1,v 1.77 2009/01/29 23:27:26 jaredy Exp $
+.\" $OpenBSD: sh.1,v 1.78 2009/02/07 07:24:37 guenther Exp $
.\"
.\" Public Domain
.\"
-.Dd $Mdocdate: January 29 2009 $
+.Dd $Mdocdate: February 7 2009 $
.Dt SH 1
.Os
.Sh NAME
@@ -1939,6 +1939,16 @@ In the future, a new option
.Pq Fl v No perhaps
will be added to distinguish the two behaviours.
.It
+.Ic echo
+options.
+In POSIX mode,
+.Fl e
+and
+.Fl E
+will not be treated as options, but printed like other arguments;
+in non-POSIX mode, these options control the interpretation
+of backslash sequences.
+.It
.Ic fg
exit status.
In POSIX mode, the exit status is 0 if no errors occur;
@@ -2326,6 +2336,10 @@ option suppresses the trailing newline,
enables backslash interpretation (a no-op, since this is normally done), and
.Fl E
suppresses backslash interpretation.
+If the
+.Ic posix
+option is set, only the first argument is treated as an option, and only
+if it is exactly ``-n''.
.Pp
.It Ic eval Ar command ...
The arguments are concatenated (with spaces between them) to form a single