SED command not being run from bash script

前端 未结 1 1060
梦如初夏
梦如初夏 2020-12-03 16:36

I have written a bash script which calls a sed command (amongst other things) on a file to complete a find/replace of 2 different strings.

The trouble is, after runn

相关标签:
1条回答
  • 2020-12-03 17:16

    Use double quotes instead of single quotes. Single quotes would prevent variable expansion.

    /usr/local/bin/sed -i -e "s/${String1}/${String1R}/g;s/\/${String2}\//\/${TString2R}\//g" ${ROOT_DIR}/data/file.sql
    

    Moreover, it seems that your variables are path strings which might contain forward slashes, i.e. /. In that event use a different separator:

    "s|${String1}|${String1R}|g"
    

    Using a different separator would obviate the need of escaping / in the pattern and replacement.

    0 讨论(0)
提交回复
热议问题