[PATCH 2/4] bin: Run scripts through shellcheck

Stephen Finucane stephen at that.guru
Tue Jan 31 10:01:43 AEDT 2017


This mostly results in the addition of quotes to prevent globbing.

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
 patchwork/bin/parsemail-batch.sh | 17 +++++++----------
 patchwork/bin/parsemail.sh       | 12 ++++++------
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/patchwork/bin/parsemail-batch.sh b/patchwork/bin/parsemail-batch.sh
index c94655b..bee047e 100755
--- a/patchwork/bin/parsemail-batch.sh
+++ b/patchwork/bin/parsemail-batch.sh
@@ -19,10 +19,9 @@
 # along with Patchwork; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-PATCHWORK_BINDIR=`dirname $0`
+PATCHWORK_BINDIR=$(dirname "$0")
 
-if [ $# -lt 1 ]
-then
+if [ $# -lt 1 ]; then
     echo "usage: $0 <dir> [options]" >&2
     exit 1
 fi
@@ -31,17 +30,15 @@ mail_dir="$1"
 
 echo "dir: $mail_dir"
 
-if [ ! -d "$mail_dir" ]
-then
+if [ ! -d "$mail_dir" ]; then
     echo "$mail_dir should be a directory"? >&2
     exit 1
 fi
 
 shift
 
-ls -1rt "$mail_dir" |
-while read line;
-do
-    echo $line
-    $PATCHWORK_BINDIR/parsemail.sh $@ < "$mail_dir/$line"
+find "$mail_dir" -maxdepth 1 |
+while read -r line; do
+    echo "$line"
+    "$PATCHWORK_BINDIR/parsemail.sh" "$@" < "$mail_dir/$line"
 done
diff --git a/patchwork/bin/parsemail.sh b/patchwork/bin/parsemail.sh
index 1ddad7f..a742f60 100755
--- a/patchwork/bin/parsemail.sh
+++ b/patchwork/bin/parsemail.sh
@@ -19,20 +19,20 @@
 # along with Patchwork; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-BIN_DIR=`dirname $0`
-PATCHWORK_BASE=`readlink -e $BIN_DIR/../..`
+BIN_DIR=$(dirname "$0")
+PATCHWORK_BASE=$(readlink -e "$BIN_DIR/../..")
 
-if [ -z $PW_PYTHON ]; then
+if [ -z "$PW_PYTHON" ]; then
     PW_PYTHON=python2
 fi
 
-if [ -z $DJANGO_SETTINGS_MODULE ]; then
+if [ -z "$DJANGO_SETTINGS_MODULE" ]; then
     DJANGO_SETTINGS_MODULE=patchwork.settings.production
 fi
 
-PYTHONPATH="$PATCHWORK_BASE":"$PATCHWORK_BASE/lib/python:$PYTHONPATH" \
+PYTHONPATH="${PATCHWORK_BASE}:${PATCHWORK_BASE}/lib/python:$PYTHONPATH" \
     DJANGO_SETTINGS_MODULE="$DJANGO_SETTINGS_MODULE" \
-    $PW_PYTHON "$PATCHWORK_BASE/manage.py" parsemail $@
+    "$PW_PYTHON" "$PATCHWORK_BASE/manage.py" parsemail "$@"
 
 # NOTE(stephenfin): We must return 0 here. When parsemail is used as a
 # delivery command from a mail server like postfix (as it is intended
-- 
2.9.3



More information about the Patchwork mailing list