function cnt_lines {
local FILE=$1
- cat $FILE | wc -l
+ wc -l < "$FILE"
}
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 {
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"