From 1ad45ecbf172bca9d3eeff8750a0eb13731c322e Mon Sep 17 00:00:00 2001 From: Jochen Nitschke Date: Wed, 11 Jan 2017 11:49:18 +0100 Subject: tdf#105204 shellcheck addressed issues in order of appearance: warnings - prefer [..] && [..] (SC2166) - unused 'awkCMD' (SC2034) - typo currentFirstLIne -> currentFirstLine (SC2154) recommendations - use $(..) instead of `..` (SC2006) - remove $ on arithmetic variable OPTIND (SC2004) - double quote to prevent globbing in $findArgs (SC2086) Change-Id: I2d2b7aecac97b2e4e0df8ce556c85995d4ecf7cf Reviewed-on: https://gerrit.libreoffice.org/33003 Reviewed-by: Michael Stahl Tested-by: Michael Stahl --- solenv/bin/add-modelines | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'solenv/bin') diff --git a/solenv/bin/add-modelines b/solenv/bin/add-modelines index fcb26bc3639d..7dff27b84382 100755 --- a/solenv/bin/add-modelines +++ b/solenv/bin/add-modelines @@ -43,10 +43,10 @@ ModelineReplace="false" function SetEnvironment() { - if [ -n "$(which tail)" -a -n "$(which head)" ]; then + if [ -n "$(which tail)" ] && [ -n "$(which head)" ]; then { - headCMD=`which head` - tailCMD=`which tail` + headCMD=$(which head) + tailCMD=$(which tail) } else { @@ -55,21 +55,13 @@ function SetEnvironment() } fi if [ -n "$(which find)" ]; then - findCMD=`which find` + findCMD=$(which find) else { echo "Missing find, exiting..." exit 1 } fi - if [ -n "$(which awk)" ]; then - awkCMD=`which awk` - else - { - echo "Missing awk, exiting..." - exit 1 - } - fi } function EditFile() @@ -80,12 +72,12 @@ function EditFile() FileToEdit="$1" - currentFirstLine=`$headCMD -1 "$FileToEdit"` - currentLastLine=`$tailCMD -1 "$FileToEdit"` + currentFirstLine=$($headCMD -1 "$FileToEdit") + currentLastLine=$($tailCMD -1 "$FileToEdit") case "$ModelineReplace" in "true" ) - if [ "${currentFirstLIne:0:6}" = "${FirstLine:0:6}" ]; then + if [ "${currentFirstLine:0:6}" = "${FirstLine:0:6}" ]; then { echo "$FirstLine" > "$FileToEdit".new $tailCMD -n +2 "$FileToEdit" >> "$FileToEdit".new @@ -144,7 +136,7 @@ while getopts "zs:p:" opt; do done if [ $OPTIND -gt 1 ]; then - shift $(($OPTIND - 1)) + shift $((OPTIND - 1)) fi if [ $# -gt 1 ]; then @@ -167,9 +159,9 @@ for FileType in ${SourceFiles}; do done # This gets rid of the final " -a " in the find argument list -findArgs="${findArgs:0:(${#findArgs}-3)}" +findArgs=(${findArgs:0:(${#findArgs}-3)}) -for file in $($findCMD $findArgs); do +for file in $($findCMD "${findArgs[@]}"); do EditFile "$file" echo "Completed: " "$file" done -- cgit