From 2add0d25a030ae29da75d19a958643466f25b8ab Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 3 Jun 2018 18:14:06 +0200 Subject: [PATCH] Use command grouping to reduce number of redirects Suggested by shellcheck and makes the code more readable. --- lib.sh | 16 +++++++++------- shell/crontab.d/setup.sh | 14 ++++++++------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib.sh b/lib.sh index bb60c52..1ce0c33 100644 --- a/lib.sh +++ b/lib.sh @@ -196,13 +196,15 @@ generate() { printf '%s: generating from "%s" (%s)\n' \ "$file" "$file$extension" "$1" - echo '###################################' >"$file" - echo '# WARNING! DO NOT EDIT THIS FILE! #' >>"$file" - echo '###################################' >>"$file" - echo >>"$file" - printf '# It was generated from "%s" on %s.\n' \ - "$file$extension" "`date`" >>"$file" - echo >>"$file" + { + echo '###################################' + echo '# WARNING! DO NOT EDIT THIS FILE! #' + echo '###################################' + echo + printf '# It was generated from "%s" on %s.\n' \ + "$file$extension" "`date`" + echo + } > "$file" file_tmp="$file" fi diff --git a/shell/crontab.d/setup.sh b/shell/crontab.d/setup.sh index 603e301..0abf260 100755 --- a/shell/crontab.d/setup.sh +++ b/shell/crontab.d/setup.sh @@ -46,12 +46,14 @@ fi # `set -e` aborts when `mktemp` fails. CRONTAB=`mktemp --tmpdir="$DIRECTORY" update-crontab.XXXXXXXXXXXX` -echo '###################################' >"$CRONTAB" -echo "$HEADER_WARNING" >>"$CRONTAB" -echo '###################################' >>"$CRONTAB" -echo >>"$CRONTAB" -printf '# It was generated from "%s/*" on %s.' \ - "$DIRECTORY" "`LANG=C date '+%a, %d %b %Y %H:%M:%S %z'`" >>"$CRONTAB" +{ + echo '###################################' + echo "$HEADER_WARNING" + echo '###################################' + echo + printf '# It was generated from "%s/*" on %s.' \ + "$DIRECTORY" "`LANG=C date '+%a, %d %b %Y %H:%M:%S %z'`" +} > "$CRONTAB" # Enforce C sort order. LC_ALL=C -- 2.45.2