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

PATCH: return status from read



Checking up on something reported on the Austin group list, I found that
the read builtin doesn't return a non-zero status when there's an error
assigning a parameter, even though the error flag is correctly set,
which is plain inconsistent.

You could argue that the builtin handler should turn a status 0 into a 1
if errflag is set on return from the builtin, but that's a bit murky.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.245
diff -p -u -r1.245 builtin.c
--- Src/builtin.c	15 Oct 2010 18:56:17 -0000	1.245
+++ Src/builtin.c	7 Jan 2011 09:55:29 -0000
@@ -5710,7 +5710,7 @@ bin_read(char *name, char **args, Option
 	}
 	return 1;
     }
-    return 0;
+    return errflag;
 }
 
 /**/
Index: Test/B04read.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/B04read.ztst,v
retrieving revision 1.4
diff -p -u -r1.4 B04read.ztst
--- Test/B04read.ztst	24 Jul 2009 18:35:53 -0000	1.4
+++ Test/B04read.ztst	7 Jan 2011 09:55:29 -0000
@@ -88,3 +88,8 @@
  print ${#line}
 0:read with trailing metafied characters
 >24  
+
+ (typeset -r foo
+  read foo) <<<bar
+1:return status on failing to set parameter
+?(eval):2: read-only variable: foo

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



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