Issue
I have file with parameters:
key1: 'testValue'
And I want to change the value of the key1
(testValue
) according to parameter.
This one is working with hard-coded value:
sed -i "s/\(key1:\).*/\1 'newValue'/" ./myFile
I tried with dynamic value:
MY_NEW_VALUE= testNewValue
sed -i "s/\(key1:\).*/\1 ${MY_NEW_VALUE}/" ./myFile
And I got am error:
sed: -e expression #1, char 32: unknown option to `s'
Solution
Working here:
root@foo:~# cat /tmp/c
key1: 'testValue'
root@foo:~# MY_NEW_VALUE="testNewValue"; cat /tmp/c | sed -s "s/\(key1:\).*/\1 '${MY_NEW_VALUE}'/"
key1: 'testNewValue'
Edit: Change your line:
MY_NEW_VALUE= testNewValue
to
MY_NEW_VALUE="testNewValue"
Answered By - TheAlphaGhost