1

For a CI / CD pipeline I would like to replace a placeholder in my nginx.conf file with a generated map which looks like the following:

map $cookie_language $lang {
  default en
  en en
  de de
  es es
}

In the nginx.conf file there is the placeholder # REPLACE_ME_WITH_LANGUAGE_MAP which I am replacing with the following command:

sed -i -e "s/# REPLACE_ME_WITH_LANGUAGE_MAP/$languagemap/g" ./ci/nginx.conf

Full script looks like the following:

languagemap='map $cookie_language $lang {'
firstlanguage=$(jq -r '.locales[0]' src/assets/locales.json | jq -r '.build')
languagemap="${languagemap}|  default   $firstlanguage"
for locale in $(jq -r '.locales[] | @base64' src/assets/locales.json); do
  lang=$(echo "$locale" | base64 --decode | jq -r '.build')
  languagemap="${languagemap}|  $lang   $lang"
  npm run ci-build -- --output-path ${OUTPUT_PATH}/$lang --configuration=${ANGULAR_CONFIGURATION} --i18n-format=xlf --i18n-file=src/locale/messages.$lang.xlf --i18n-locale=$lang
done
languagemap="${languagemap}|}"
sed -i "t" "s/# REPLACE_ME_WITH_LANGUAGE_MAP/$languagemap/g" ./ci/nginx.conf

Running this always brings up:

+ sed -i tmp s/# REPLACE_ME_WITH_LANGUAGE_MAP/map $cookie_language $lang {|  default   en|  en   en|  de   de|}/g ./ci/nginx.conf
sed: can't find label for jump to `mp'

What's the point?

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
  • 't' can be a sed branch command. From what you show us, I can't see where it is triggered, but I'd bet the 2c on that – Laurent G Aug 14 '19 at 09:48
  • Possible duplicate of [sed replace with variable with multiple lines](https://stackoverflow.com/questions/6684487/sed-replace-with-variable-with-multiple-lines) – Toby Speight Aug 14 '19 at 13:06

1 Answers1

0

The 10th line of your full script is

sed -i "t" <replace-command-script> <input-file>

and sed correctly interpters the "t" as a "branch to" command, which throws an error.

Replace this line with the variant you have provided above, namely

sed -i -e '<replace command script>' <input-file>

This should fix the problem.

tripleee
  • 175,061
  • 34
  • 275
  • 318
KMZ
  • 463
  • 3
  • 12