From: Jorge Hernandez Date: Fri, 4 Aug 2017 21:26:24 +0000 (-0500) Subject: [POLICY-145] sed failed expanding special chars X-Git-Tag: v1.1.0~41 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=dc4ffa2b8d51ec96a7032db5c619eb991862322e;p=policy%2Fdocker.git [POLICY-145] sed failed expanding special chars The install script fails when expanding configuration variables with special characters, for example the delimiter. This fix' scope is for the replacement string escaping. Change-Id: Icfe8d89b46c7720bf5effaa2f3add6a19e2af2d2 Signed-off-by: Jorge Hernandez --- diff --git a/policy-drools/docker-install.sh b/policy-drools/docker-install.sh index cedb2121..aaa3d10d 100644 --- a/policy-drools/docker-install.sh +++ b/policy-drools/docker-install.sh @@ -144,7 +144,7 @@ function configure_component() { set -x fi - local CONF_FILE COMPONENT_ROOT_DIR name value + local CONF_FILE COMPONENT_ROOT_DIR SED_LINE SED_FILES name value CONF_FILE=$1 COMPONENT_ROOT_DIR=$2 @@ -157,16 +157,15 @@ function configure_component() { SED_LINE+=" -e 's!\${{JAVA_HOME}}!${JAVA_HOME}!g' " while read line || [ -n "${line}" ]; do - if [[ -n $line ]] && [[ $line != *#* ]]; then + if [[ -n ${line} ]] && [[ ${line:0:1} != \# ]]; then name=$(echo "${line%%=*}") value=$(echo "${line#*=}") # escape ampersand so that sed does not replace it with the search string - value=${value//&/\\&} + value=$(echo "${value}" | sed -e 's/[\/&]/\\&/g') if [[ -z ${name} ]] || [[ -z ${value} ]]; then echo "WARNING: ${line} missing name or value" fi - SED_LINE+=" -e 's!\${{${name}}}!${value}!g' " - + SED_LINE+=" -e 's/\${{${name}}}/${value}/g' " fi done < "$CONF_FILE"