将sed与包含点的变量一起使用

问题描述:

我试图在文件中用6.1替换(例如)6.0,而不用6.1替换640

I am trying to replace (for instance) 6.0 by 6.1 in a file, without 640 being replaced by 6.1

我目前有:

sed -i "s/$previousName/$newName/" 'myFile'

我认为解决方案可以在此处,但我找不到正确的解决方案.

I think that the solution could be in here, but I don't find the right solution.

EDIT 这两个字符串都在变量内,并且应该重复的问题不会处理这种情况

EDIT both string are inside a variable and the question this is supposed to be a duplicate of doesn't treat this case

使用内部 sed :

sed -i "s@$(echo $previousName | sed 's/\./\\./g')@$newName@g" myFile