Sed bash replace containing a path pattern

45 Views Asked by At

I'm attempting to replace a string on bash script with the following

 sed -i -e \"s/__BUILD_NUMBER__/${version}.${BUILD_NUMBER}/g\" -e \"s/__BUILD_TIMESTAMP__/${BUILD_TIMESTAMP}/g\" package.json

But I'm getting the following error

sed: -e expression #1, char 24: unknown option to `s'

these are the values of the variables

version= ase/bab/BAB

BUILD_NUMBER= 2.11.0.7

BUILD_TIMESTAMP= 2024-03-27_14-37-04

2

There are 2 best solutions below

0
Balázs Ruda On

I guess your command should be corret.You need to escape the sashes in your variabl with backslash:

version=ase\/bab\/BAB
0
Yuri G. On

use # as a delimiter

sed -i -e "s#__BUILD_NUMBER__#${version}.${BUILD_NUMBER}#g" -e "s#__BUILD_TIMESTAMP__#${BUILD_TIMESTAMP}#g" package.json