diff options
author | Janos Gyerik <janos.gyerik@sonarsource.com> | 2018-01-12 15:52:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-12 15:52:19 +0100 |
commit | 8149055e1f45ba97698409b5672d750a109a5f32 (patch) | |
tree | d0ad4d22f8546f3d73fcd6719c83608bd505ece5 /scripts | |
parent | 4340fe6bec625e71ef95bbb165219557d6f190e1 (diff) | |
download | sonarqube-8149055e1f45ba97698409b5672d750a109a5f32.tar.gz sonarqube-8149055e1f45ba97698409b5672d750a109a5f32.zip |
Fix quoting issues causing a failure in OSX, and other quality issues (#2851)
* Avoid useless cat
* Properly quote command line arguments
* Use [ \t] instead of \s for BSD sed
* Do not delete commented out property settings, by matching strictly at start of line
* Add forgotten double-quotes
* Explicitly escape \t (advice by shellcheck.net)
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/property_utils.sh | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/scripts/property_utils.sh b/scripts/property_utils.sh index 035ce53ba07..86ba82da643 100755 --- a/scripts/property_utils.sh +++ b/scripts/property_utils.sh @@ -10,7 +10,7 @@ set -euo pipefail function cnt_lines { local FILE=$1 - cat $FILE | wc -l + wc -l < "$FILE" } function write_prop { @@ -21,8 +21,8 @@ function write_prop { # uncomment below to help debug calls to set_property #echo "setting property $PROPERTY to value $VALUE in $FILE" - echo "" >> $FILE - echo "${PROPERTY}=${VALUE}" >> $FILE + echo >> "$FILE" + echo "${PROPERTY}=${VALUE}" >> "$FILE" } function set_property { @@ -30,20 +30,20 @@ function set_property { local VALUE=$2 local FILE=$3 - local REGEXP="${PROPERTY//\./\\.}\\s*=" + local REGEXP="^${PROPERTY//\./\\.}[ \\t]*=" if grep -q "$REGEXP" "$FILE"; then # delete line of specified property - LINE_COUNT=$(cnt_lines $FILE) + LINE_COUNT=$(cnt_lines "$FILE") if [[ "$OSTYPE" == "darwin"* ]]; then - sed -i '' /${REGEXP}/d "$FILE" + sed -i '' "/${REGEXP}/d" "$FILE" else - sed -i /${REGEXP}/d "$FILE" + sed -i "/${REGEXP}/d" "$FILE" fi # add property if at least one line deleted - local NEW_LINE_COUNT=$(cnt_lines $FILE) + local NEW_LINE_COUNT=$(cnt_lines "$FILE") if [[ $LINE_COUNT -gt $NEW_LINE_COUNT ]]; then write_prop "$PROPERTY" "$VALUE" "$FILE" |