diff mbox series

Cleaner error messages

Message ID 1548691104.3758682.1645313288.2864B6B8@webmail.messagingengine.com (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show
Series Cleaner error messages | expand

Commit Message

Olivier Duclos Jan. 28, 2019, 3:58 p.m. UTC
Hi,

This is a small cosmetic patch which fixes something that annoyed me for a long time: the repetition of the script name in error messages.

Example:

  $ cat test.sh
  #!/bin/sh
  echo ${x:?}

  $ dash test.sh
  /home/odc/test.sh: 2: /home/odc/test.sh: x: parameter not set or null

With the patch:

  $ dash test.sh
  /home/odc/test.sh: 2: x: parameter not set or null

This is the same behavior as bash.
diff mbox series

Patch

diff --git a/src/error.c b/src/error.c
index 728ff88..ed35256 100644
--- a/src/error.c
+++ b/src/error.c
@@ -46,6 +46,7 @@ 
 #include "jobs.h"
 #include "shell.h"
 #include "main.h"
+#include "mystring.h"
 #include "options.h"
 #include "output.h"
 #include "error.h"
@@ -124,7 +125,7 @@  exvwarning2(const char *msg, va_list ap)
 
        errs = out2;
        name = arg0 ? arg0 : "sh";
-       if (!commandname)
+       if (!commandname || equal(commandname, name))
                fmt = "%s: %d: ";
        else
                fmt = "%s: %d: %s: ";