Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh Don't output the error for bad usage (no var name given)



details:   https://anonhg.NetBSD.org/src/rev/4f3247f40e15
branches:  trunk
changeset: 369464:4f3247f40e15
user:      kre <kre%NetBSD.org@localhost>
date:      Fri Aug 19 12:52:31 2022 +0000

description:
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]

diffstat:

 bin/sh/miscbltin.c |  11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diffs (37 lines):

diff -r 04fcd711df7a -r 4f3247f40e15 bin/sh/miscbltin.c
--- a/bin/sh/miscbltin.c        Fri Aug 19 12:49:55 2022 +0000
+++ b/bin/sh/miscbltin.c        Fri Aug 19 12:52:31 2022 +0000
@@ -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 @@
                        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";
 



Home | Main Index | Thread Index | Old Index