2

I 've got a file named file.conf containing:

this is the configuration text and this is the WORD to change.

Running:

sed -i 's/WORD/"ONE TWO"/g' file.conf 

I will have file.conf modified:

this is the configuration text and this is the "ONE TWO" to change.

now if I make a script, using read:

read -p 'word to change' TEXT -> "ONE TWO"
echo $TEXT -> "ONE TWO" 
sed -i 's/WORD/'$TEXT'/g' file.conf

it does not work with error message:

sed: -e expression #1, char 11: unterminated `s' command

file.conf is not modified in this case.

but it works if I read $TEXT with only one word without spaces: "ONE" for instance.

Thanx folks.

1

1 Answer 1

1

Double quote variable like this:

sed -i 's/WORD/'"$TEXT"'/g' file.conf

Even safer:

sed -i 's/WORD/'"${TEXT}"'/g' file.conf
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.