Subject: patch to make sh -u work
To: None <tech-userlevel@netbsd.org>
From: Ben Harris <bjh21@netbsd.org>
List: tech-userlevel
Date: 05/14/2002 00:11:16
I'm not quite sure why, but I seem to have cooked up a patch to get sh -u
(complain when using an unset variable) to work.  I'm a little lacking in
shell-internals clue, though, so could someone who understands it check I
haven't missed something vital?  What few regression tests we've got for
sh still seem to pass afterwards.

Index: expand.c
===================================================================
RCS file: /cvsroot/basesrc/bin/sh/expand.c,v
retrieving revision 1.52
diff -u -r1.52 expand.c
--- expand.c	2001/09/19 06:38:19	1.52
+++ expand.c	2002/05/13 23:01:51
@@ -657,6 +657,17 @@
 	}
 	varlen = 0;
 	startloc = expdest - stackblock();
+	if (!set && uflag)
+		switch (subtype) {
+		case VSNORMAL:
+		case VSTRIMLEFT:
+		case VSTRIMLEFTMAX:
+		case VSTRIMRIGHT:
+		case VSTRIMRIGHTMAX:
+		case VSLENGTH:
+			error("%.*s: parameter not set", p - var - 1, var);
+			/* NOTREACHED */
+		}
 	if (set && subtype != VSPLUS) {
 		/* insert the value of the variable */
 		if (special) {
Index: sh.1
===================================================================
RCS file: /cvsroot/basesrc/bin/sh/sh.1,v
retrieving revision 1.46
diff -u -r1.46 sh.1
--- sh.1	2002/02/24 21:41:52	1.46
+++ sh.1	2002/05/13 23:01:52
@@ -201,7 +201,6 @@
 .It Fl u Em nounset
 Write a message to standard error when attempting to expand a variable
 that is not set, and if the shell is not interactive, exit immediately.
-(UNIMPLEMENTED for 4.4alpha)
 .It Fl v Em verbose
 The shell writes its input to standard error as it is read.  Useful for
 debugging.

-- 
Ben Harris                                                   <bjh21@netbsd.org>
Portmaster, NetBSD/acorn26           <URL:http://www.netbsd.org/Ports/acorn26/>