From 4049649ea8b17af92affc6ec2bb2f86063497e6e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 28 Oct 2022 09:42:10 +1030 Subject: [PATCH] check: fix warnings from shellcheck 0.8.0 And make errors gcc-style, so emacs can jump through the automatically. ``` In devtools/reduce-includes.sh line 21: echo -n "-$LINE" ^-- SC3037 (warning): In POSIX sh, echo flags are undefined. In devtools/reduce-includes.sh line 25: echo -n "." ^-- SC3037 (warning): In POSIX sh, echo flags are undefined. In tools/rel.sh line 6: prefix=$(printf '%s\n' "${from#$common}" | sed 's@[^/][^/]*@..@g') ^-----^ SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns. Did you mean: prefix=$(printf '%s\n' "${from#"$common"}" | sed 's@[^/][^/]*@..@g') In tools/rel.sh line 7: printf '%s\n' "$prefix/${to#$common}" ^-----^ SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns. Did you mean: printf '%s\n' "$prefix/${to#"$common"}" For more information: https://www.shellcheck.net/wiki/SC3037 -- In POSIX sh, echo flags are undef... https://www.shellcheck.net/wiki/SC2295 -- Expansions inside ${..} need to b... make: *** [Makefile:553: check-shellcheck] Error 123 ``` Signed-off-by: Rusty Russell --- Makefile | 2 +- devtools/reduce-includes.sh | 7 +++---- tools/rel.sh | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index bc7983ec17c5..7f26ebf2272c 100644 --- a/Makefile +++ b/Makefile @@ -550,7 +550,7 @@ check-cppcheck: .cppcheck-suppress @trap 'rm -f .cppcheck-suppress' 0; git ls-files -- "*.c" "*.h" | grep -vE '^ccan/' | xargs cppcheck ${CPPCHECK_OPTS} check-shellcheck: - @git ls-files -- "*.sh" | xargs shellcheck + @git ls-files -- "*.sh" | xargs shellcheck -f gcc check-setup_locale: @tools/check-setup_locale.sh diff --git a/devtools/reduce-includes.sh b/devtools/reduce-includes.sh index c71cf32b4de7..81e4f8770c3e 100755 --- a/devtools/reduce-includes.sh +++ b/devtools/reduce-includes.sh @@ -17,12 +17,11 @@ for file; do grep -F -v "$LINE" "$file" > "$file".c if $CCMD /tmp/out.$$.o "$file".c 2>/dev/null; then - # shellcheck disable=SC2039 - echo -n "-$LINE" + printf "%s" "-$LINE" mv "$file".c "$file" else - # shellcheck disable=SC2039 - echo -n "." + # shellcheck disable=SC2039,SC3037 + printf "." rm -f "$file".c i=$((i + 1)) fi diff --git a/tools/rel.sh b/tools/rel.sh index e27b7467cc8a..8d1fd4262509 100755 --- a/tools/rel.sh +++ b/tools/rel.sh @@ -3,5 +3,5 @@ from=${1} to=${2} common=$(printf '%s\n%s' "${from}" "${to}" | sed 'N;s/\(.*\).*\n\1.*$/\1/' | sed 's@/[^/]*$@/@') -prefix=$(printf '%s\n' "${from#$common}" | sed 's@[^/][^/]*@..@g') -printf '%s\n' "$prefix/${to#$common}" +prefix=$(printf '%s\n' "${from#"$common"}" | sed 's@[^/][^/]*@..@g') +printf '%s\n' "$prefix/${to#"$common"}"