Handle the case where grep operates on an empty file

There are cases when grepping for an option in the config file where
grep will not find it, which is fine in this case, but without adjusting
the exit code in that case it can make an entire script bail out.
This commit is contained in:
Kyle Rankin 2018-12-06 16:10:10 -08:00
parent dd3f650b81
commit 1e9491f98d
No known key found for this signature in database
GPG Key ID: 555577116BFA74B9

View File

@ -228,7 +228,7 @@ replace_config() {
awk "gsub(\"^${CONFIG_OPTION}=.*\",\"${CONFIG_OPTION}=\\\"${NEW_SETTING}\\\"\")" /tmp/config >> ${CONFIG_FILE}.tmp
# then copy any remaining settings from the existing config file, minus the option you changed
grep -v "^export ${CONFIG_OPTION}=" ${CONFIG_FILE} | grep -v "^${CONFIG_OPTION}=" >> ${CONFIG_FILE}.tmp
grep -v "^export ${CONFIG_OPTION}=" ${CONFIG_FILE} | grep -v "^${CONFIG_OPTION}=" >> ${CONFIG_FILE}.tmp || true
mv ${CONFIG_FILE}.tmp ${CONFIG_FILE}
}