Module Name:    src
Committed By:   kre
Date:           Fri Aug 19 12:52:32 UTC 2022

Modified Files:
        src/bin/sh: miscbltin.c

Log Message:
Don't output the error for bad usage (no var name given)
after already writing the prompt (set with the -p option).

That results in nonsense like:

        $ read -p foo
        fooread: arg count

While here, improve the error message so it means something.

Now we will get:

$ read -p foo
read: variable name required
Usage: read [-r] [-p prompt] var...

[Detected by code reading while doing the work for the previous fix]


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/bin/sh/miscbltin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/miscbltin.c
diff -u src/bin/sh/miscbltin.c:1.51 src/bin/sh/miscbltin.c:1.52
--- src/bin/sh/miscbltin.c:1.51	Fri Aug 19 12:17:18 2022
+++ src/bin/sh/miscbltin.c	Fri Aug 19 12:52:31 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: miscbltin.c,v 1.51 2022/08/19 12:17:18 kre Exp $	*/
+/*	$NetBSD: miscbltin.c,v 1.52 2022/08/19 12:52:31 kre Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)miscbltin.c	8.4 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: miscbltin.c,v 1.51 2022/08/19 12:17:18 kre Exp $");
+__RCSID("$NetBSD: miscbltin.c,v 1.52 2022/08/19 12:52:31 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -111,14 +111,15 @@ readcmd(int argc, char **argv)
 			rflag = 1;
 	}
 
+	if (*(ap = argptr) == NULL)
+		error("variable name required\n"
+			"Usage: read [-r] [-p prompt] var...");
+
 	if (prompt && isatty(0)) {
 		out2str(prompt);
 		flushall();
 	}
 
-	if (*(ap = argptr) == NULL)
-		error("arg count");
-
 	if ((ifs = bltinlookup("IFS", 1)) == NULL)
 		ifs = " \t\n";
 

Reply via email to