From e37a6401cdf02af2815e3ee04f81462941e8ce1c Mon Sep 17 00:00:00 2001 From: Alfred Klomp Date: Mon, 23 May 2022 00:18:10 +0200 Subject: [PATCH] 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"