lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 6bde648 05/10: Print zsh script name when she


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 6bde648 05/10: Print zsh script name when shellcheck fails
Date: Thu, 26 Sep 2019 09:40:21 -0400 (EDT)

branch: master
commit 6bde648d96756e6b8866fe6cc42b19f28ca835e0
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Print zsh script name when shellcheck fails
---
 check_script.sh | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/check_script.sh b/check_script.sh
index 1bfe7fe..910c0b7 100755
--- a/check_script.sh
+++ b/check_script.sh
@@ -41,12 +41,25 @@ esac
 
 # First line, truncated at its first blank:
 shebang="$(sed -e'1!d' -e's/ .*$//' "$1")"
+
+# For scripts beginning with '#!/bin/zsh', a pipeline changes that
+# hashbang to '#!/bin/sh' and feeds the result into shellcheck.
+# In that case, any errors are reported as occurring in file '-',
+# so the command below writes the name of the zsh script after any
+# error messages.
+#
+# A fancier alternative might postprocess shellcheck output thus:
+#  | sed -e"/^In - line [0-9]*:$/s/-/$1"
+# but that would be harder to maintain, and more fragile because
+# the format of shellcheck's output might change in future.
+
 case $shebang  in
     ("#!/bin/sh")
         shellcheck --external-sources "$1"
     ;;
     ("#!/bin/zsh")
-        sed -e'1s/zsh/sh/' "$1" | shellcheck --external-sources -
+        sed -e'1s/zsh/sh/' "$1" | shellcheck --external-sources - \
+          || { printf '%s\n' "...in file $1"; exit 0; }
     ;;
     ("#!/usr/bin/make") ;;
     ("#!/bin/sed") ;;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]