sed variable expansion not working (unterminated `s' command)

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 Answer

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like