I have 1 file and hope use sed to replace the string.
a.txt
#define 1
#define 2
b.sh
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
MODEL_NAME='123 %s abc 3.0 %d <<456: %s>>'
sed -i 's/#define 1/#define 1 \"'${MODEL_NAME}'\"/g' 1.txt
My expect result in 1.txt:
#define 1 "123 %s abc 3.0 %d <<456: %s>>"
#define 2
But I got the error message from console:
sed: -e expression #1, char 27: unterminated `s' command
Could someone help explain the condition for this? thanks.
Because you are using single quotes around your sed command, the shell variable ${MODEL_NAME} never gets expanded. Try:
sed -i "s/#define 1/#define 1 \"${MODEL_NAME}\"/g" 1.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With