Replace one substring for another string in shell script

前端 未结 10 1627
猫巷女王i
猫巷女王i 2020-11-22 11:55

I have \"I love Suzi and Marry\" and I want to change \"Suzi\" to \"Sara\".

#!/bin/bash
firstString=\"I love Suzi and Marry\"
secondString=\"Sara\"
# do some         


        
10条回答
  •  鱼传尺愫
    2020-11-22 12:30

    Since I can't add a comment. @ruaka To make the example more readable write it like this

    full_string="I love Suzy and Mary"
    search_string="Suzy"
    replace_string="Sara"
    my_string=${full_string/$search_string/$replace_string}
    or
    my_string=${full_string/Suzy/Sarah}
    

提交回复
热议问题