From 0e13634759deb2e3c6925c01b6045d241e9d230a Mon Sep 17 00:00:00 2001 From: Alfred Klomp Date: Mon, 23 May 2022 00:13:21 +0200 Subject: [PATCH 1/4] shellcheck: double-quote arguments Shellcheck advises: SC2086: Double quote to prevent globbing and word splitting. --- shrinkpdf.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shrinkpdf.sh b/shrinkpdf.sh index 20d5328..b72c0d1 100644 --- a/shrinkpdf.sh +++ b/shrinkpdf.sh @@ -41,11 +41,11 @@ shrink () -dSubsetFonts=true \ -dAutoRotatePages=/None \ -dColorImageDownsampleType=/Bicubic \ - -dColorImageResolution=$3 \ + -dColorImageResolution="$3" \ -dGrayImageDownsampleType=/Bicubic \ - -dGrayImageResolution=$3 \ + -dGrayImageResolution="$3" \ -dMonoImageDownsampleType=/Subsample \ - -dMonoImageResolution=$3 \ + -dMonoImageResolution="$3" \ -sOutputFile="$2" \ "$1" } From 12f53df10ec668d9a39d6809237359ce3cceb28d Mon Sep 17 00:00:00 2001 From: Alfred Klomp Date: Mon, 23 May 2022 00:14:18 +0200 Subject: [PATCH 2/4] shellcheck: use well-defined OR comparison Shellcheck advises: SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined. --- shrinkpdf.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shrinkpdf.sh b/shrinkpdf.sh index b72c0d1..6b45375 100644 --- a/shrinkpdf.sh +++ b/shrinkpdf.sh @@ -54,7 +54,7 @@ check_smaller () { # If $1 and $2 are regular files, we can compare file sizes to # see if we succeeded in shrinking. If not, we copy $1 over $2: - if [ ! -f "$1" -o ! -f "$2" ]; then + if [ ! -f "$1" ] || [ ! -f "$2" ]; then return 0; fi ISIZE="$(echo $(wc -c "$1") | cut -f1 -d\ )" From d5f605a06ad1d7bdaaff30a064b81fc22ca921c8 Mon Sep 17 00:00:00 2001 From: Alfred Klomp Date: Mon, 23 May 2022 00:15:39 +0200 Subject: [PATCH 3/4] shellcheck: avoid unnecessary negation Shellcheck advises: SC2236: Use -n instead of ! -z. --- shrinkpdf.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shrinkpdf.sh b/shrinkpdf.sh index 6b45375..0a4c5de 100644 --- a/shrinkpdf.sh +++ b/shrinkpdf.sh @@ -81,14 +81,14 @@ if [ -z "$IFILE" ]; then fi # Output filename defaults to "-" (stdout) unless given: -if [ ! -z "$2" ]; then +if [ -n "$2" ]; then OFILE="$2" else OFILE="-" fi # Output resolution defaults to 72 unless given: -if [ ! -z "$3" ]; then +if [ -n "$3" ]; then res="$3" else res="72" From e37a6401cdf02af2815e3ee04f81462941e8ce1c Mon Sep 17 00:00:00 2001 From: Alfred Klomp Date: Mon, 23 May 2022 00:18:10 +0200 Subject: [PATCH 4/4] shellcheck: avoid unnecessary echo Shellcheck advises: SC2005: Useless echo? Instead of 'echo $(cmd)', just use 'cmd'. The extra echo was added in 9bd52f as a workaround for `wc' in OSX, which printed extra whitespace before the character count. Fix this issue in a different way by piping the `wc' output through `awk'. This also means that we no longer use the suggested workaround, so remove the dangling acknowledgement. --- README.md | 3 --- shrinkpdf.sh | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 29604e9..7c0719e 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,3 @@ The script is licensed under the I didn't invent the wheel, just packaged it nicely. All credits go to the [Ghostscript](http://www.ghostscript.com) team. - -Many thanks to Dr. Alun J. Carr for fixing a portability issue on Mac OS X -regarding leading whitespace in the output of `wc`. diff --git a/shrinkpdf.sh b/shrinkpdf.sh index 0a4c5de..a0cc947 100644 --- a/shrinkpdf.sh +++ b/shrinkpdf.sh @@ -57,8 +57,8 @@ check_smaller () if [ ! -f "$1" ] || [ ! -f "$2" ]; then return 0; fi - ISIZE="$(echo $(wc -c "$1") | cut -f1 -d\ )" - OSIZE="$(echo $(wc -c "$2") | cut -f1 -d\ )" + ISIZE="$(wc -c "$1" | awk '{ print $1 }')" + OSIZE="$(wc -c "$2" | awk '{ print $1 }')" if [ "$ISIZE" -lt "$OSIZE" ]; then echo "Input smaller than output, doing straight copy" >&2 cp "$1" "$2"