0

I have a file named config.yaml that contains this line:

device_connection_string: "<ADD DEVICE CONNECTION STRING HERE>"

I want to replace <ADD DEVICE CONNECTION STRING HERE> with the value of the following variable:

root@ubuntu1804-ko-001:/tmp# echo "$CSTRING"

HostName=PulseAzure-BetterTogetherDemo.azure-devices.net;DeviceId=ubuntu1804-ko-001;SharedAccessKey=xdWDu2gnzlg8X1mHgGqYU+yECBYUJ065n1AjdkYNCWI=
root@ubuntu1804-ko-001:/tmp#

When I run this sed command, I get the unterminated s error:

sed -i "s/<ADD DEVICE CONNECTION STRING HERE>/$CSTRING/g" config.yaml
sed: -e expression #1, char 38: unterminated `s' command

Thank you for your help!

5
  • 1
    Does your CSTRING have an extra trailing newline by any chance? Please edit your question to include the output of echo "$CSTRING" | xxd (being sure to include the quotes) May 17, 2019 at 23:20
  • Looks like it might be a preceding newline...? Updated Question via edit. Thank you.
    – Ken
    May 17, 2019 at 23:25
  • Yes, that would do it also May 17, 2019 at 23:27
  • Thank you very much for your help!!! Is there some way I can give you credit when marking this as answered...? (I'm new here).
    – Ken
    May 17, 2019 at 23:31
  • Thanks - I have added a brief answer below in case someone else finds it useful May 17, 2019 at 23:42

1 Answer 1

1

It turns out that CSTRING contains a literal newline.

By enabling shell debugging we can see what sed sees:

$ set -x
$ sed "s/<ADD DEVICE CONNECTION STRING HERE>/$CSTRING/g" config.yaml
+ sed 's/<ADD DEVICE CONNECTION STRING HERE>/
HostName=PulseAzure-BetterTogetherDemo.azure-devices.net;DeviceId=ubuntu1804-ko-001;SharedAccessKey=xdWDu2gnzsfsdfdsfds=/g' config.yaml

and it's the sed 's/<ADD DEVICE CONNECTION STRING HERE>/ that is causing the

sed: -e expression #1, char 38: unterminated `s' command

error.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .