-2

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'
Biffen
  • 6,249
  • 6
  • 28
  • 36
user1365697
  • 5,819
  • 15
  • 60
  • 96

1 Answers1

0

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"
TheAlphaGhost
  • 151
  • 10