From a3b5e77c6c4a8183585c15867374039712212f12 Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 24 Mar 2013 15:01:50 +0000 Subject: [PATCH] disable parsing of &> as GNU bash iop if -o posix or -o sh, based on IRC discussion where jilles(IIRC) pointed out it breaks existing valid scripts --- check.t | 21 ++++++++++++++++++--- lex.c | 5 +++-- mksh.1 | 9 ++++++++- sh.h | 4 ++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/check.t b/check.t index 518e09f..a09e85e 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.600 2013/03/24 00:56:19 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.601 2013/03/24 15:01:46 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -29,7 +29,7 @@ # http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD expected-stdout: - @(#)MIRBSD KSH R44 2013/03/23 + @(#)MIRBSD KSH R44 2013/03/24 description: Check version of shell. stdin: @@ -38,7 +38,7 @@ name: KSH_VERSION category: shell:legacy-no --- expected-stdout: - @(#)LEGACY KSH R44 2013/03/23 + @(#)LEGACY KSH R44 2013/03/24 description: Check version of legacy shell. stdin: @@ -8511,6 +8511,21 @@ expected-stdout: ras dwa --- +name: bashiop-5 +description: + Check if GNU bash-like I/O redirection is only supported + in !POSIX !sh mode as it breaks existing scripts' syntax + (tested only on MirBSD as it uses /dev/fd) +category: os:mirbsd +stdin: + "$__progname" -c 'echo foo>/dev/null&>/dev/fd/2 echo bar1' + "$__progname" -o posix -c 'echo foo>/dev/null&>/dev/fd/2 echo bar2' + "$__progname" -o sh -c 'echo foo>/dev/null&>/dev/fd/2 echo bar3' +expected-stderr: + foo echo bar1 + bar2 + bar3 +--- name: mkshiop-1 description: Check for support of more than 9 file descriptors diff --git a/lex.c b/lex.c index 3f60742..98719fe 100644 --- a/lex.c +++ b/lex.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.182 2013/02/19 18:45:20 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.183 2013/03/24 15:01:48 tg Exp $"); /* * states while lexing word @@ -898,7 +898,8 @@ yylex(int cf) state = SBASE; dp = Xstring(ws, wp); - if ((c == '<' || c == '>' || c == '&') && state == SBASE) { + if (state == SBASE && (c == '<' || c == '>' || + (!Flag(FSH) && !Flag(FPOSIX) && c == '&'))) { struct ioword *iop = alloc(sizeof(struct ioword), ATEMP); if (Xlength(ws, wp) == 0) diff --git a/mksh.1 b/mksh.1 index 2d7f2bf..d73dd5c 100644 --- a/mksh.1 +++ b/mksh.1 @@ -1,4 +1,4 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.306 2013/03/24 00:56:23 tg Exp $ +.\" $MirOS: src/bin/mksh/mksh.1,v 1.307 2013/03/24 15:01:49 tg Exp $ .\" $OpenBSD: ksh.1,v 1.145 2013/01/17 21:20:25 jmc Exp $ .\"- .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, @@ -2434,6 +2434,13 @@ in .Nm but a syntax error in GNU .Nm bash . +Setting the +.Fl o Ar posix +or +.Fl o Ar sh +shell options disable parsing of this redirection; +it's a compatibility feature to legacy scripts, to +not be used when writing new shell code. .It Xo .No &\*(Gt\*(Ba Ar file , .No &\*(Gt\*(Gt Ar file , diff --git a/sh.h b/sh.h index 4d4f3bf..ec81ca5 100644 --- a/sh.h +++ b/sh.h @@ -164,9 +164,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.643 2013/03/24 00:56:25 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.644 2013/03/24 15:01:50 tg Exp $"); #endif -#define MKSH_VERSION "R44 2013/03/23" +#define MKSH_VERSION "R44 2013/03/24" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES