Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Anonymous function with redirection and arguments



On Mon, 8 May 2017 02:47:41 +0000
Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> $ zsh -f
> % () { echo foo $1 } >1; cat 1; rm -f 1    
> foo
> % () { echo foo $1 } bar >1; cat 1; rm -f 1 
> foo bar
> % () { echo foo $1 } >1 bar; cat 1; rm -f 1
> zsh: parse error near `bar'
> % 
> 
> It shouldn't parse error, should it?

There's no obvious reason why they shouldn't be mixed.

pws

diff --git a/Src/parse.c b/Src/parse.c
index 83e87af..b0de9a8 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -2030,10 +2030,21 @@ par_simple(int *cmplx, int nr)
 		/* Unnamed function */
 		int parg = ecadd(0);
 		ecadd(0);
-		while (tok == STRING) {
-		    ecstr(tokstr);
-		    argc++;
-		    zshlex();
+		while (tok == STRING || IS_REDIROP(tok)) {
+		    if (tok == STRING)
+		    {
+			ecstr(tokstr);
+			argc++;
+			zshlex();
+		    } else {
+			*cmplx = c = 1;
+			nrediradd = par_redir(&r, NULL);
+			p += nrediradd;
+			if (ppost)
+			    ppost += nrediradd;
+			sr += nrediradd;
+			parg += nrediradd;
+		    }
 		}
 		if (argc > 0)
 		    *cmplx = 1;
diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst
index a5de552..2671080 100644
--- a/Test/A04redirect.ztst
+++ b/Test/A04redirect.ztst
@@ -475,6 +475,18 @@
 >Nothing output yet
 >I just read any old rubbish
 
+  print you cannot be serious >input1
+  () {
+    local var
+    read var
+    print $1 $var $2
+  } <input1 Shirley >output1 dude
+  print Nothing output yet
+  cat output1
+0:anonymous function redirections mixed with argument
+>Nothing output yet
+>Shirley you cannot be serious dude
+
   redirfn() {
     local var
     read var



Messages sorted by: Reverse Date, Date, Thread, Author