[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master d4aeb8d 1/6: Improve shellcheck usage
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master d4aeb8d 1/6: Improve shellcheck usage |
Date: |
Thu, 26 Aug 2021 20:48:05 -0400 (EDT) |
branch: master
commit d4aeb8d5aad4118ce9e4e01884a9dc04170a9cbb
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Improve shellcheck usage
Replaced a workaround with '--shell='.
---
check_script.sh | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/check_script.sh b/check_script.sh
index 24f2412..5c56641 100755
--- a/check_script.sh
+++ b/check_script.sh
@@ -42,24 +42,17 @@ 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.
+# Treat scripts beginning with '#!/bin/zsh' as though the shebang
+# were '#!/bin/sh', writing shellcheck directives wherever
+# zsh-specific features are used. See:
+# https://lists.nongnu.org/archive/html/lmi/2021-08/msg00011.html
case $shebang in
("#!/bin/sh")
shellcheck --external-sources "$1"
;;
("#!/bin/zsh")
- sed -e'1s/zsh/sh/' "$1" | shellcheck --external-sources - \
- || { printf '%s\n' "...in file $1"; exit 0; }
+ shellcheck --external-sources --shell="sh" "$1"
;;
("#!/usr/bin/make") ;;
("#!/bin/sed") ;;
- [lmi-commits] [lmi] master updated (8fd99ca -> 9e68ef8), Greg Chicares, 2021/08/26
- [lmi-commits] [lmi] master 144c075 5/6: Make a unit-test function return a useful value, Greg Chicares, 2021/08/26
- [lmi-commits] [lmi] master 0215566 4/6: Further improve a local function in a unit-test TU, Greg Chicares, 2021/08/26
- [lmi-commits] [lmi] master d4aeb8d 1/6: Improve shellcheck usage,
Greg Chicares <=
- [lmi-commits] [lmi] master 166571d 3/6: Improve a local function in a unit-test TU, Greg Chicares, 2021/08/26
- [lmi-commits] [lmi] master 9e68ef8 6/6: Add TOMS 748 unit tests, Greg Chicares, 2021/08/26
- [lmi-commits] [lmi] master 11df70d 2/6: Assert nonnegativity of certain unit-test parameters, Greg Chicares, 2021/08/26