[jhbuild/wip/lantw/fix-warnings-reported-by-shellcheck: 3/3] Fix warnings reported by shellcheck



commit 9a812d11a6eef31eafad52efc7f39828896aea35
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Sat Sep 21 01:05:36 2019 +0800

    Fix warnings reported by shellcheck
    
    SC2006: Use $(...) notation instead of legacy backticked `...`.
    SC2039: In POSIX sh, echo flags are undefined.
    SC2039: In POSIX sh, string replacement is undefined.
    SC2048: Use "$@" (with quotes) to prevent whitespace problems.
    SC2086: Double quote to prevent globbing and word splitting.
    SC2129: Consider using { cmd1; cmd2; } >> file instead of individual redirects.
    SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
    SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.
    SC2206: Quote to prevent word splitting, or split robustly with mapfile or read -a.
    SC2230: which is non-standard. Use builtin 'command -v' instead.
    SC2231: Quote expansions in this for loop glob to prevent wordsplitting, e.g. "$dir"/*.txt .
    SC2234: Remove superfluous (..) around test command.
    SC2241: The exit status can only be one integer 0-255. Use stdout for other data.

 autogen.sh                                       | 108 +++++++++++------------
 contrib/jhbuild_completion.bash                  |  10 +--
 scripts/branch-violations/find-branch-violations |   4 +-
 scripts/create-master-tracking-moduleset.sh      |   8 +-
 scripts/debian-python2-postinstall-hook.sh       |   4 +-
 tests/autotools/autogen.sh                       |   2 +-
 tests/hello/autogen.sh                           |   4 +-
 tests/libhello/autogen.sh                        |   4 +-
 triggers/glib.trigger                            |   2 +-
 triggers/gtk+.trigger                            |   6 +-
 triggers/mime-database.trigger                   |   2 +-
 triggers/texinfo-dir.trigger                     |   8 +-
 12 files changed, 81 insertions(+), 81 deletions(-)
---
diff --git a/autogen.sh b/autogen.sh
index 69d30991..e13c3023 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -35,7 +35,7 @@ PKG_NAME=jhbuild
 FALSE=1
 TRUE=0
 
-srcdir=`dirname $0`
+srcdir=$(dirname "$0")
 test -z "$srcdir" && srcdir=.
 test -z "$MAKE" && MAKE=make
 
@@ -47,18 +47,18 @@ setup_i18n()
 
   # Build mo from po files so i18n works for this script. mo files can't be
   # checked in to git so they must be built here.
-  if [ $msgfmtl_available -eq 0 ]; then
+  if [ "$msgfmtl_available" -eq 0 ]; then
     # -s is for silent
     # -C is for change directory
-    $make_from_environment -s -C $srcdir/po -f Makefile.plain
+    "$make_from_environment" -s -C "$srcdir/po" -f Makefile.plain
   fi
 
   # Check gettext.sh is installed to provide i18n for this script
   hash gettext.sh 2>&-
   gettext_sh_available=$?
 
-  if [ $gettext_sh_available -eq 0 ]; then
-    export TEXTDOMAINDIR=$srcdir/mo
+  if [ "$gettext_sh_available" -eq 0 ]; then
+    export TEXTDOMAINDIR="$srcdir/mo"
     export TEXTDOMAIN=jhbuild
 
     . gettext.sh
@@ -109,42 +109,43 @@ configure_without_autotools()
 
   # setup the defaults. The following can changed from the commandline.
   # e.g. ./autogen.sh --prefix=${HOME}/jhbuildhome
-  [ -z $prefix ] && prefix=${HOME}/.local
-  [ -z $bindir ] && bindir=${prefix}/bin
-  [ -z $datarootdir ] && datarootdir=${prefix}/share
-  [ -z $desktopdir ] && desktopdir=${datarootdir}/applications
+  [ -z "$prefix" ] && prefix=${HOME}/.local
+  [ -z "$bindir" ] && bindir=${prefix}/bin
+  [ -z "$datarootdir" ] && datarootdir=${prefix}/share
+  [ -z "$desktopdir" ] && desktopdir=${datarootdir}/applications
 
   # Check to see if $srcdir/Makefile.inc is writable
-  if [ -f $srcdir/Makefile.inc ]; then
-    if [ ! -w $srcdir/Makefile.inc ]; then
+  if [ -f "$srcdir/Makefile.inc" ]; then
+    if [ ! -w "$srcdir/Makefile.inc" ]; then
       eval_gettext  "Unable to create file \$srcdir/Makefile.inc"; echo
       exit 1
     fi
   else
-    if [ ! -w $srcdir ]; then
+    if [ ! -w "$srcdir" ]; then
       eval_gettext  "Unable to create file \$srcdir/Makefile.inc"; echo
       exit 1
     fi
   fi
 
-  echo "# This file is automatically generated by JHBuild's autogen.sh" \
-    > $srcdir/Makefile.inc
-  echo "# Do NOT edit. This file will be overwritten when autogen.sh is next" \
-       "run." >> $srcdir/Makefile.inc
-  echo "prefix=$prefix" >> $srcdir/Makefile.inc
-  echo "bindir=$bindir" >> $srcdir/Makefile.inc
-  echo "datarootdir=$datarootdir" >> $srcdir/Makefile.inc
-  echo "desktopdir=$desktopdir" >> $srcdir/Makefile.inc
-  if [ $msgfmtl_available -ne 0 ]; then
-      echo "DISABLE_GETTEXT=yes" >> $srcdir/Makefile.inc
-  fi
+  {
+    echo "# This file is automatically generated by JHBuild's autogen.sh"
+    echo "# Do NOT edit. This file will be overwritten when autogen.sh is next" \
+         "run."
+    echo "prefix=$prefix"
+    echo "bindir=$bindir"
+    echo "datarootdir=$datarootdir"
+    echo "desktopdir=$desktopdir"
+    if [ "$msgfmtl_available" -ne 0 ]; then
+        echo "DISABLE_GETTEXT=yes"
+    fi
+  } > "$srcdir/Makefile.inc"
 
-  if [ ! -f $makefile ]; then
+  if [ ! -f "$makefile" ]; then
     eval_gettext "Unable to read file \$makefile"; echo
     exit 1
   fi
 
-  cp $makefile $srcdir/Makefile || {
+  cp "$makefile" "$srcdir/Makefile" || {
     eval_gettext "Unable to copy \$makefile to \$srcdir/Makefile"
     echo
     exit 1
@@ -159,15 +160,15 @@ configure_with_autotools()
   test -d m4 || mkdir m4
   test -d build-aux || mkdir build-aux
 
-  (test -f $srcdir/configure.ac) || {
-    echo "**Error**: Directory "\`$srcdir\'" does not look like the top-level project directory"
+  test -f "$srcdir/configure.ac" || {
+    echo "**Error**: Directory \"\`$srcdir'\" does not look like the top-level project directory"
     exit 1
   }
 
-  if [ "$#" = 0 -a "x$NOCONFIGURE" = "x" ]; then
+  if [ "$#" = 0 ] && [ "x$NOCONFIGURE" = "x" ]; then
     echo "**Warning**: I am going to run \`configure' with no arguments." >&2
     echo "If you wish to pass any to it, please specify them on the" >&2
-    echo \`$0\'" command line." >&2
+    echo "\`$0' command line." >&2
     echo "" >&2
   fi
 
@@ -177,10 +178,10 @@ configure_with_autotools()
   ( cd "$srcdir" && autoreconf --verbose --force --install -Wno-portability ) || exit 1
 
   if [ "$NOCONFIGURE" = "" ]; then
-    $srcdir/configure "$@" || exit 1
+    "$srcdir/configure" "$@" || exit 1
 
-    if [ "$1" = "--help" ]; then exit 0 else
-      echo "Now type \`make\' to compile $PKG_NAME" || exit 1
+    if [ "$1" = "--help" ]; then exit 0; else
+      echo "Now type \`make' to compile $PKG_NAME" || exit 1
     fi
   else
     echo "Skipping configure process."
@@ -191,9 +192,8 @@ configure_with_autotools()
 
 # Check for make. make is required to provide i18n for this script and to
 # build and install JHBuild
-make_from_environment=`echo $MAKE | cut -d' ' -f1`
-hash $make_from_environment 2>&-
-if [ $? -ne 0 ]; then
+make_from_environment=$(echo "$MAKE" | cut -d' ' -f1)
+if ! hash "$make_from_environment" 2>&-; then
   echo "\`$make_from_environment' is required to configure & build $PKG_NAME"
   exit 1
 fi
@@ -201,16 +201,16 @@ fi
 setup_i18n
 if [ $gettext_available -ne 0 ]; then
   # If gettext is not installed fallback to echo in english
-  gettext() { echo -n $1; }
+  gettext() { printf '%s' "$1"; }
   # eval_gettext substitutes variables of the form: \$var
   eval_gettext()
   {
-    escaped_string=${1/\'/\\\'}
-    eval echo -n ${escaped_string/\`/\\\`}
+    escaped_string=$(echo "$1" | sed -e "s/\'/\\\'/g" -e "s/\`/\\\\\`/g")
+    eval "printf '%s' ${escaped_string}"
   }
 fi
 
-if [ ! -f $srcdir/jhbuild/main.py ]; then
+if [ ! -f "$srcdir/jhbuild/main.py" ]; then
   eval_gettext "**Error**: Directory \`\$srcdir' does not look like the top-level \$PKG_NAME directory"
   echo
   exit 1
@@ -234,14 +234,14 @@ autopoint_available=$?
 hash yelp-build 2>&-
 yelp_tools_available=$?
 
-parse_commandline $*
+parse_commandline "$@"
 
 autotools_dependencies_met=$FALSE
-if [ $autoconf_available -eq $TRUE -a \
-     $automake_available -eq $TRUE -a \
-     $pkg_config_available -eq $TRUE -a \
-     $autopoint_available -eq $TRUE -a \
-     $yelp_tools_available -eq $TRUE ]; then
+if [ "$autoconf_available" -eq "$TRUE" ] && \
+   [ "$automake_available" -eq "$TRUE" ] && \
+   [ "$pkg_config_available" -eq "$TRUE" ] && \
+   [ "$autopoint_available" -eq "$TRUE" ] && \
+   [ "$yelp_tools_available" -eq "$TRUE" ]; then
     autotools_dependencies_met=$TRUE
 fi
 
@@ -254,29 +254,29 @@ if test -n "$NOCONFIGURE"; then
 fi
 
 use_autotools=$FALSE
-if [ $enable_autotools -eq $TRUE -a $autotools_dependencies_met -eq $TRUE ]; then
+if [ "$enable_autotools" -eq "$TRUE" ] && [ "$autotools_dependencies_met" -eq "$TRUE" ]; then
   use_autotools=$TRUE
 fi
-if [ $force_autotools -eq $TRUE ]; then
+if [ "$force_autotools" -eq "$TRUE" ]; then
   use_autotools=$TRUE
 fi
 
-if [ $use_autotools -eq $TRUE ]; then
-  configure_with_autotools $*
+if [ "$use_autotools" -eq "$TRUE" ]; then
+  configure_with_autotools "$@"
 else
-  if [ $autoconf_available -ne $TRUE ]; then
+  if [ "$autoconf_available" -ne "$TRUE" ]; then
     gettext "WARNING: aclocal not available (usually part of package 'autoconf')"; echo
   fi
-  if [ $automake_available -ne $TRUE ]; then
+  if [ "$automake_available" -ne "$TRUE" ]; then
     gettext "WARNING: automake not available (usually part of package 'automake')"; echo
   fi
-  if [ $autopoint_available -ne $TRUE ]; then
+  if [ "$autopoint_available" -ne "$TRUE" ]; then
     gettext "WARNING: autopoint not available (usually part of package 'gettext')"; echo
   fi
-  if [ $pkg_config_available -ne $TRUE ]; then
+  if [ "$pkg_config_available" -ne "$TRUE" ]; then
     gettext "WARNING: pkg-config not available (usually part of package 'pkgconfig')"; echo
   fi
-  if [ $yelp_tools_available -ne $TRUE ]; then
+  if [ "$yelp_tools_available" -ne "$TRUE" ]; then
     gettext "WARNING: yelp-tools not available (usually part of package 'yelp-tools')"; echo
   fi
   configure_without_autotools
diff --git a/contrib/jhbuild_completion.bash b/contrib/jhbuild_completion.bash
index ed2787b0..2d2ed330 100644
--- a/contrib/jhbuild_completion.bash
+++ b/contrib/jhbuild_completion.bash
@@ -38,11 +38,11 @@ _jhbuild()
        update|updateone|build|buildone|list|dot|info|-t|-s|-a|-n|-c)
                # FIXME: some of these options can take multiple module names
                # give them a list of modules
-               command_list="`jhbuild list -a`"
+               command_list="$(jhbuild list -a)"
                ;;
        run)
                # give them a list of commands
-               COMP_WORDS=(COMP_WORDS[0] $cur)
+               COMP_WORDS=("${COMP_WORDS[0]}" "$cur")
                COMP_CWORD=1
                _command
                ;;
@@ -58,7 +58,7 @@ _jhbuild()
                command_list="gui update updateone build buildone tinderbox run shell sanitycheck bootstrap 
list dot info"
 
                v=false
-               if [ $COMP_CWORD -gt 2 ]; then
+               if [ "$COMP_CWORD" -gt 2 ]; then
                        for i in $command_list; do
                                if [ "${COMP_WORDS[COMP_CWORD-2]}" == "$i" ]; then
                                        v=true
@@ -67,7 +67,7 @@ _jhbuild()
                        done
                fi
                
-               if $v; then
+               if "$v"; then
                        command_list=""
                fi
                ;;
@@ -75,7 +75,7 @@ _jhbuild()
        
        for i in $command_list; do
                if [ -z "${i/$cur*}" ]; then
-                       COMPREPLY=( ${COMPREPLY[@]} $i )
+                       COMPREPLY=( "${COMPREPLY[@]}" "$i" )
                fi
        done
 }
diff --git a/scripts/branch-violations/find-branch-violations 
b/scripts/branch-violations/find-branch-violations
index f711ffc3..0a9f4d20 100755
--- a/scripts/branch-violations/find-branch-violations
+++ b/scripts/branch-violations/find-branch-violations
@@ -13,12 +13,12 @@ branch="gnome-${branch//./-}"
 
 join \
      <( # list of modules defined in jhbuild without branch tag
-       "`dirname "$0"`/find-branch-moduleset" "$branch" |
+       "$(dirname "$0")/find-branch-moduleset" "$branch" |
        grep "<cvsmodule" |
        grep -v "$branch" |
        sed 's/.*cvsmodule.*id="\([^"]*\)".*/\1/' |
        sort
       ) \
      <( # list of modules in CVS with branch tag
-       "`dirname "$0"`/find-branch-modules" "$branch"
+       "$(dirname "$0")/find-branch-modules" "$branch"
       )
diff --git a/scripts/create-master-tracking-moduleset.sh b/scripts/create-master-tracking-moduleset.sh
index dc3657db..cc73caea 100755
--- a/scripts/create-master-tracking-moduleset.sh
+++ b/scripts/create-master-tracking-moduleset.sh
@@ -2,11 +2,11 @@
 
 VERSION=$(grep '^moduleset =' jhbuild/defaults.jhbuildrc | awk -F"-"  '{ print $NF }' | sed -e "s/'//g")
 
-for FILENAME in modulesets/*-$VERSION.modules
+for FILENAME in modulesets/*-"$VERSION".modules
 do
-    TRUNK_FILENAME=$(echo $FILENAME | sed -e "s/$VERSION/trunk/")
+    TRUNK_FILENAME=$(echo "$FILENAME" | sed -e "s/$VERSION/trunk/")
     xsltproc --nodtdattr scripts/create-master-tracking-moduleset.xsl \
-        $FILENAME > $TRUNK_FILENAME
-    sed -i -e "s/-$VERSION.modules/-trunk.modules/" $TRUNK_FILENAME
+        "$FILENAME" > "$TRUNK_FILENAME"
+    sed -i -e "s/-$VERSION.modules/-trunk.modules/" "$TRUNK_FILENAME"
 done
 
diff --git a/scripts/debian-python2-postinstall-hook.sh b/scripts/debian-python2-postinstall-hook.sh
index 0666ca62..772e9911 100755
--- a/scripts/debian-python2-postinstall-hook.sh
+++ b/scripts/debian-python2-postinstall-hook.sh
@@ -10,14 +10,14 @@ set -e
 
 BINDIR=$1
 DEST="$BINDIR/python2"
-PYTHON=$(which python 2>/dev/null || true);
+PYTHON=$(command -v python 2>/dev/null || true);
 
 die() { echo "$1" >&2 ; exit 2; }
 
 test -n "$BINDIR" || die "Usage: $0 BINDIR"
 test -d "$BINDIR" || die "$0: '$BINDIR' is not a directory"
 
-which python2 2>/dev/null && exit 0 # 'python2' is already on PATH
+command -v python2 2>/dev/null && exit 0 # 'python2' is already on PATH
 
 test -x "$PYTHON" || die "$0: Unable to find 'python' in the PATH"
 
diff --git a/tests/autotools/autogen.sh b/tests/autotools/autogen.sh
index 4f5da01e..b471f609 100755
--- a/tests/autotools/autogen.sh
+++ b/tests/autotools/autogen.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-srcdir=`dirname $0`
+srcdir=$(dirname "$0")
 test -z "$srcdir" && srcdir=. 
 
 aclocal
diff --git a/tests/hello/autogen.sh b/tests/hello/autogen.sh
index 4f5da01e..50dfb242 100644
--- a/tests/hello/autogen.sh
+++ b/tests/hello/autogen.sh
@@ -1,10 +1,10 @@
 #!/bin/sh
 
-srcdir=`dirname $0`
+srcdir=$(dirname "$0")
 test -z "$srcdir" && srcdir=. 
 
 aclocal
 automake --add-missing
 autoconf
 
-exec $srcdir/configure "$@"
+exec "$srcdir/configure" "$@"
diff --git a/tests/libhello/autogen.sh b/tests/libhello/autogen.sh
index 1a45039b..a7d4edc4 100644
--- a/tests/libhello/autogen.sh
+++ b/tests/libhello/autogen.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-srcdir=`dirname $0`
+srcdir=$(dirname "$0")
 test -z "$srcdir" && srcdir=. 
 
 libtoolize
@@ -8,4 +8,4 @@ aclocal
 automake --add-missing
 autoconf
 
-exec $srcdir/configure "$@"
+exec "$srcdir/configure" "$@"
diff --git a/triggers/glib.trigger b/triggers/glib.trigger
index 5524ac48..954d42d3 100644
--- a/triggers/glib.trigger
+++ b/triggers/glib.trigger
@@ -19,4 +19,4 @@
 # IfExecutable: glib-compile-schemas
 # REMatch: ^share/glib-2.0/schemas/
 
-glib-compile-schemas $JHBUILD_PREFIX/share/glib-2.0/schemas
+glib-compile-schemas "$JHBUILD_PREFIX/share/glib-2.0/schemas"
diff --git a/triggers/gtk+.trigger b/triggers/gtk+.trigger
index 968ce9d4..833466d4 100644
--- a/triggers/gtk+.trigger
+++ b/triggers/gtk+.trigger
@@ -19,8 +19,8 @@
 # IfExecutable: gtk-update-icon-cache
 # REMatch: ^share/icons/
 
-for dir in $JHBUILD_PREFIX/share/icons/*; do
-  if test -f $dir/index.theme; then
-    gtk-update-icon-cache --quiet $dir
+for dir in "$JHBUILD_PREFIX/share/icons/"*; do
+  if test -f "$dir/index.theme"; then
+    gtk-update-icon-cache --quiet "$dir"
   fi
 done
diff --git a/triggers/mime-database.trigger b/triggers/mime-database.trigger
index e680795e..8734818d 100644
--- a/triggers/mime-database.trigger
+++ b/triggers/mime-database.trigger
@@ -19,4 +19,4 @@
 # IfExecutable: update-mime-database
 # REMatch: /mime/packages/.*\.xml
 
-update-mime-database $JHBUILD_PREFIX/share/mime
+update-mime-database "$JHBUILD_PREFIX/share/mime"
diff --git a/triggers/texinfo-dir.trigger b/triggers/texinfo-dir.trigger
index 4b2acae7..725dda0c 100644
--- a/triggers/texinfo-dir.trigger
+++ b/triggers/texinfo-dir.trigger
@@ -19,8 +19,8 @@
 # IfExecutable: install-info
 # REMatch: ^share/info/.*\.info
 
-rm -f $JHBUILD_PREFIX/share/info/dir-new
-for info in $JHBUILD_PREFIX/share/info/*.info; do
-  install-info $info $JHBUILD_PREFIX/share/info/dir-new
+rm -f "$JHBUILD_PREFIX/share/info/dir-new"
+for info in "$JHBUILD_PREFIX/share/info/"*.info; do
+  install-info "$info" "$JHBUILD_PREFIX/share/info/dir-new"
 done
-mv $JHBUILD_PREFIX/share/info/dir-new $JHBUILD_PREFIX/share/info/dir
+mv "$JHBUILD_PREFIX/share/info/dir-new" "$JHBUILD_PREFIX/share/info/dir"


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