There is no harm in quoting variables, it clearly marks the end of a
variable name and silences shellcheck warnings.

E.g. TMPFILE is set by mktemp which uses the user-controlled TMPDIR
variable. There might be strange people out there who use whitespace
characters in their TMPDIR name making the script break.

Add a comment and ignore the warning where we really do not want quotes.
---
 check_sec.sh                  | 12 +++++++-----
 contrib/bgedit-screen-tmux.sh |  4 ++--
 contrib/iconv/make.sh         | 11 +++++------
 doc/instdoc.sh.in             |  2 +-
 mkchangelog.sh                |  2 +-
 mkreldate.sh                  |  2 +-
 6 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/check_sec.sh b/check_sec.sh
index 03bf2188..e9c0262d 100755
--- a/check_sec.sh
+++ b/check_sec.sh
@@ -15,18 +15,20 @@ do_check_files ()
         msg="$1" ; shift
         grep -En "$pattern" "$@"               | \
                 grep -v '^[^    ]*:[^  ]*#'    | \
-                grep -Fv "$magic" > $TMPFILE
+                grep -Fv "$magic" > "$TMPFILE"
 
-        test -s $TMPFILE && {
+        test -s "$TMPFILE" && {
                 echo "$msg" ;
-                cat $TMPFILE;
-                rm -f $TMPFILE;
+                cat "$TMPFILE"
+                rm -f "$TMPFILE"
                 RV=1;
         }
 }
 
 do_check ()
 {
+        # We rely on .c files having sane filenames, ignore warning.
+        # shellcheck disable=SC2046
         do_check_files "$1" "$2" "$3" $(find . -name '*.c' -print)
 }
 
@@ -44,5 +46,5 @@ do_check '\<isspace' __SAFE_ISSPACE_CHECKED__ "You probably 
meant IS_ASCII_WS he
 do_check_files '\<(malloc|realloc|free|strdup)[        ]*\(' __MEM_CHECKED__ 
"Alert: Use of traditional memory management calls." \
         ./*.c imap/*.c autocrypt/*.c
 
-rm -f $TMPFILE
+rm -f "$TMPFILE"
 exit $RV
diff --git a/contrib/bgedit-screen-tmux.sh b/contrib/bgedit-screen-tmux.sh
index 5124d957..2adeebc3 100644
--- a/contrib/bgedit-screen-tmux.sh
+++ b/contrib/bgedit-screen-tmux.sh
@@ -52,9 +52,9 @@ $editor "\$@"
 exitval=\$?
 END_SCRIPT
 
-if test x$STY != x; then
+if test x"$STY" != x; then
   screen -X screen /bin/sh "$tmpdir/run" "$@"
-elif test x$TMUX != x; then
+elif test x"$TMUX" != x; then
   tmux neww /bin/sh "$tmpdir/run" "$@"
 else
   echo "Not running inside a terminal emulator" >&2
diff --git a/contrib/iconv/make.sh b/contrib/iconv/make.sh
index 1382b151..0ed94162 100755
--- a/contrib/iconv/make.sh
+++ b/contrib/iconv/make.sh
@@ -9,18 +9,17 @@
 #
 
 LIBICONV=$1
-test -d $LIBICONV/libcharset/tools || {
+test -d "$LIBICONV"/libcharset/tools || {
        echo "Sorry, I can't find libiconv's source!" >&2 ; 
        exit 1 ;
 }
 
-# shellcheck disable=SC2231
-for f in $LIBICONV/libcharset/tools/* ; do
+for f in "$LIBICONV"/libcharset/tools/* ; do
        rm -f tmp.rc.
-       ( head -3 $f | grep -q 'locale name.*locale charmap.*locale_charset' ) 
&& (
-               sed '1,/^$/d' $f | awk '($4 != $3) { printf ("iconv-hook %s 
%s\n", $4, $3); }' | \
+       ( head -3 "$f" | grep -q 'locale name.*locale charmap.*locale_charset' 
) && (
+               sed '1,/^$/d' "$f" | awk '($4 != $3) { printf ("iconv-hook %s 
%s\n", $4, $3); }' | \
                        sed -e 's/^iconv-hook SJIS /iconv-hook Shift_JIS /gi' |
                        sort -u > tmp.rc )
-       test -s tmp.rc && mv tmp.rc iconv.$(basename $f).rc
+       test -s tmp.rc && mv tmp.rc iconv."$(basename "$f")".rc
        rm -f tmp.rc
 done
diff --git a/doc/instdoc.sh.in b/doc/instdoc.sh.in
index 09d932ce..a2fe7a51 100644
--- a/doc/instdoc.sh.in
+++ b/doc/instdoc.sh.in
@@ -21,6 +21,6 @@ rm -f "$TARGET"
 
 sed -e "s;/usr/local/bin/;$bindir/;g"          \
     -e "s;/usr/local/doc/mutt/;$docdir/;g"     \
-    "$SOURCE" > $TARGET
+    "$SOURCE" > "$TARGET"
 
 chmod 644 "$TARGET"
diff --git a/mkchangelog.sh b/mkchangelog.sh
index 9f551012..209e01f6 100755
--- a/mkchangelog.sh
+++ b/mkchangelog.sh
@@ -14,4 +14,4 @@ lrev=$(git describe --tags --match 'mutt-*-rel' --abbrev=0)
 # anymore to make it worth the effort.
 git log --name-status \
     --pretty=format:"%ai  %an  <%ae> (%h)%n%n%w(,8,8)* %s%n%+b" \
-    ${lrev}^..
+    "$lrev"^..
diff --git a/mkreldate.sh b/mkreldate.sh
index b9be6373..246c2f55 100755
--- a/mkreldate.sh
+++ b/mkreldate.sh
@@ -8,4 +8,4 @@ else
   reldate=$(head -n 1 ChangeLog | LC_ALL=C cut -d ' ' -f 1)
 fi
 
-echo $reldate
+echo "$reldate"
-- 
2.51.0

Reply via email to