there’s no evidence for -e in any BSD echo (but in ksh93 print)

spotted by Jean Delvare <jdelvare@suse.de> and Werner Fink <werner@suse.de>
This commit is contained in:
tg
2017-02-17 22:28:26 +00:00
parent ca6529e0a2
commit 287507fb21
2 changed files with 41 additions and 53 deletions

61
funcs.c
View File

@@ -38,7 +38,7 @@
#endif #endif
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.320 2017/02/08 15:27:27 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.321 2017/02/17 22:28:25 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
/* /*
@@ -307,8 +307,6 @@ c_print(const char **wp)
bool hist; bool hist;
/* print words as wide characters? */ /* print words as wide characters? */
bool chars; bool chars;
/* print a "--" argument? */
bool pminusminus;
/* writing to a coprocess (SIGPIPE blocked)? */ /* writing to a coprocess (SIGPIPE blocked)? */
bool coproc; bool coproc;
bool copipe; bool copipe;
@@ -323,43 +321,36 @@ c_print(const char **wp)
if (wp[0][0] == 'e') { if (wp[0][0] == 'e') {
/* "echo" builtin */ /* "echo" builtin */
++wp;
#ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT
if (Flag(FSH)) {
/*
* MidnightBSD /bin/sh needs a BSD echo, that is,
* one that supports -e but does not enable it by
* default
*/
po.exp = false;
}
#endif
if (Flag(FPOSIX) || if (Flag(FPOSIX) ||
#ifndef MKSH_MIDNIGHTBSD01ASH_COMPAT #ifndef MKSH_MIDNIGHTBSD01ASH_COMPAT
Flag(FSH) || Flag(FSH) ||
#endif #endif
Flag(FAS_BUILTIN)) { Flag(FAS_BUILTIN)) {
/* Debian Policy 10.4 compliant "echo" builtin */ /* BSD "echo" cmd, Debian Policy 10.4 compliant */
++wp;
bsd_echo:
if (*wp && !strcmp(*wp, "-n")) { if (*wp && !strcmp(*wp, "-n")) {
/* recognise "-n" only as the first arg */
po.nl = false; po.nl = false;
++wp; ++wp;
} }
/* print everything as-is */
po.exp = false; po.exp = false;
} else { } else {
bool new_exp = po.exp, new_nl = po.nl; bool new_exp, new_nl = true;
/** /*-
* a compromise between sysV and BSD echo commands: * compromise between various historic echos: only
* escape sequences are enabled by default, and -n, * recognise -Een if they appear in arguments with
* -e and -E are recognised if they appear in argu- * no illegal options; e.g. echo -nq outputs '-nq'
* ments with no illegal options (ie, echo -nq will
* print -nq).
* Different from sysV echo since options are reco-
* gnised, different from BSD echo since escape se-
* quences are enabled by default.
*/ */
#ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT
/* MidnightBSD /bin/sh needs -e supported but off */
if (Flag(FSH))
new_exp = false;
else
#endif
/* otherwise compromise on -e enabled by default */
new_exp = true;
goto print_tradparse_beg;
print_tradparse_arg: print_tradparse_arg:
if ((s = *wp) && *s++ == '-' && *s) { if ((s = *wp) && *s++ == '-' && *s) {
@@ -375,6 +366,7 @@ c_print(const char **wp)
new_nl = false; new_nl = false;
goto print_tradparse_ch; goto print_tradparse_ch;
case '\0': case '\0':
print_tradparse_beg:
po.exp = new_exp; po.exp = new_exp;
po.nl = new_nl; po.nl = new_nl;
++wp; ++wp;
@@ -384,11 +376,9 @@ c_print(const char **wp)
} }
} else { } else {
/* "print" builtin */ /* "print" builtin */
const char *opts = "AclNnpRrsu,"; const char *opts = "AcelNnpRrsu,";
const char *emsg; const char *emsg;
po.pminusminus = false;
while ((c = ksh_getopt(wp, &builtin_opt, opts)) != -1) while ((c = ksh_getopt(wp, &builtin_opt, opts)) != -1)
switch (c) { switch (c) {
case 'A': case 'A':
@@ -417,11 +407,9 @@ c_print(const char **wp)
} }
break; break;
case 'R': case 'R':
/* fake BSD echo command */ /* fake BSD echo but don't reset other flags */
po.pminusminus = true; wp += builtin_opt.optind;
po.exp = false; goto bsd_echo;
opts = "en";
break;
case 'r': case 'r':
po.exp = false; po.exp = false;
break; break;
@@ -445,8 +433,7 @@ c_print(const char **wp)
if (wp[builtin_opt.optind] && if (wp[builtin_opt.optind] &&
ksh_isdash(wp[builtin_opt.optind])) ksh_isdash(wp[builtin_opt.optind]))
builtin_opt.optind++; builtin_opt.optind++;
} else if (po.pminusminus) }
builtin_opt.optind--;
wp += builtin_opt.optind; wp += builtin_opt.optind;
} }

33
mksh.1
View File

@@ -1,8 +1,8 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.422 2017/02/17 20:41:56 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.423 2017/02/17 22:28:26 tg Exp $
.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $ .\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
.\"- .\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
.\" 2010, 2011, 2012, 2013, 2014, 2015, 2016 .\" 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
.\" mirabilos <m@mirbsd.org> .\" mirabilos <m@mirbsd.org>
.\" .\"
.\" Provided that these terms and disclaimer and all copyright notices .\" Provided that these terms and disclaimer and all copyright notices
@@ -3421,8 +3421,10 @@ If the
.Ic posix .Ic posix
or or
.Ic sh .Ic sh
option is set or this is a direct builtin call, only the first argument option is set or this is a direct builtin call or
is treated as an option, and only if it is exactly .Ic print
.Fl R ,
only the first argument is treated as an option, and only if it is exactly
.Dq Li \-n . .Dq Li \-n .
Backslash interpretation is disabled. Backslash interpretation is disabled.
.Pp .Pp
@@ -3758,12 +3760,12 @@ however, distributors may have added this as builtin as a speed hack.
.It Xo .It Xo
.Ic print .Ic print
.Oo Fl AclNnprsu Ns Oo Ar n Oc \*(Ba .Oo Fl AclNnprsu Ns Oo Ar n Oc \*(Ba
.Fl R Op Fl en Oc .Fl R Op Fl n Oc
.Op Ar argument ... .Op Ar argument ...
.Xc .Xc
Print the specified argument(s) on the standard output, Print the specified argument(s) on the standard output,
separated by spaces, terminated with a newline. separated by spaces, terminated with a newline.
The C escapes mentioned in The escapes mentioned in
.Sx Backslash expansion .Sx Backslash expansion
above, as well as above, as well as
.Dq Li \ec , .Dq Li \ec ,
@@ -3789,6 +3791,9 @@ utility, tab completion, the
built-in utility and the built-in utility and the
.Ic select .Ic select
statement do. statement do.
.It Fl e
Restore backslash expansion after a previous
.Fl r .
.It Fl l .It Fl l
Change the output word separator to newline. Change the output word separator to newline.
.It Fl N .It Fl N
@@ -3811,17 +3816,13 @@ instead of standard output.
.Pp .Pp
The The
.Fl R .Fl R
option is used to emulate, to some degree, the option mostly emulates the
.Bx .Bx
.Xr echo 1 .Xr echo 1
command which does not process command which does not expand backslashes and interprets
.Ql \e its first argument as option only if it is exactly
sequences unless the .Dq Li \-n
.Fl e .Pq to suppress the trailing newline .
option is given.
As above, the
.Fl n
option suppresses the trailing newline.
.Pp .Pp
.It Ic pwd Op Fl LP .It Ic pwd Op Fl LP
Print the present working directory. Print the present working directory.
@@ -6696,7 +6697,7 @@ for the in-memory portion of the history is slow, should use
.Xr memmove 3 . .Xr memmove 3 .
.Pp .Pp
This document attempts to describe This document attempts to describe
.Nm mksh\ R54 .Nm mksh\ R55
and up, and up,
.\" with vendor patches from insert-your-name-here, .\" with vendor patches from insert-your-name-here,
compiled without any options impacting functionality, such as compiled without any options impacting functionality, such as