Replace string in linux bash

This question already has an answer here:

  • How to escape single quotes within single quoted strings? 19 answers

  • Use double-quotes around sed for variable expansion & to preserve single quotes.

    sed -i "s/os.path.join(BASE_DIR, 'db.sqlite3'),/$project_name,/g" "$project_name/settings.py"
    

    tested working fine on GNU sed version 4.2.1


    You should escape the quotes in 'db.sqlite3' :

    sudo sed -i 's/os.path.join(BASE_DIR, '''db.sqlite3'''),/'$project_name',/g' $projects_name/settings.py
    

    Your sed pattern is os.path.join(BASE_DIR, db.sqlite3), because quotes in 'db.sqlite3' are not interpreted as literal ' . Instead they close and reopen the sed command.

    链接地址: http://www.djcxy.com/p/57136.html

    上一篇: 命令通过'bash失败

    下一篇: 在linux bash中替换字符串