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' commandThank you for your help!
51 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.yamland it's the sed 's/<ADD DEVICE CONNECTION STRING HERE>/ that is causing the
sed: -e expression #1, char 38: unterminated `s' commanderror.