[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") ;;
- [lmi-commits] [lmi] master updated (6557d30 -> 5ae814c), Greg Chicares, 2019/09/26
- [lmi-commits] [lmi] master 6bde648 05/10: Print zsh script name when shellcheck fails,
Greg Chicares <=
- [lmi-commits] [lmi] master dba418b 02/10: Source 'lmi_setup_inc' in every other 'lmi_setup*' script, Greg Chicares, 2019/09/26
- [lmi-commits] [lmi] master 13972c4 06/10: Enable verbose tracing in 'lmi_setup*.sh', Greg Chicares, 2019/09/26
- [lmi-commits] [lmi] master 8838b01 07/10: Make sure each 'lmi_setup*' script is run in the right environment, Greg Chicares, 2019/09/26
- [lmi-commits] [lmi] master 96e0911 08/10: Prefer https to http, Greg Chicares, 2019/09/26
- [lmi-commits] [lmi] master 5ae814c 10/10: Prepare to test scripted chroot creation, Greg Chicares, 2019/09/26
- [lmi-commits] [lmi] master c1cbb7f 04/10: Start writing a master 'lmi_setup*' script to call the others, Greg Chicares, 2019/09/26
- [lmi-commits] [lmi] master 890f9e3 01/10: Augment redhat notes, Greg Chicares, 2019/09/26
- [lmi-commits] [lmi] master 606a0cf 09/10: Reuse an existing debootstrap tarball if available, Greg Chicares, 2019/09/26
- [lmi-commits] [lmi] master 8e2ced7 03/10: Improve 'lmi_setup_*.sh', notably resolving shellcheck issues, Greg Chicares, 2019/09/26