ZhangZhihui's Blog  

The problem is with slashes: your variable contains them and the final command will be something like sed "s/string/path/to/something/g", containing way too many slashes.

Since sed can take any char as delimiter (without having to declare the new delimiter), you can try using another one that doesn't appear in your replacement string:

replacement="/my/path"
sed --expression "s@pattern@$replacement@"
/home/scnzzh/zzh $> sed 's@/PATH@/path@' b.txt
binpath=/path/TO/SCRIPTS/
aa_binpath=/path/TO/AA/

/home/scnzzh/zzh $> sed 's|/PATH|/path|' b.txt
binpath=/path/TO/SCRIPTS/
aa_binpath=/path/TO/AA/

 

posted on 2020-12-25 12:32  ZhangZhihuiAAA  阅读(1030)  评论(0编辑  收藏  举报