String difference in Bash

后端 未结 5 917
借酒劲吻你
借酒劲吻你 2020-12-04 06:31

I\'m trying to find a way to determine the difference between two strings in my script. I could easily do this with diff or comm, but I\'m not dealing with files and I\'d pr

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 07:28

    Say you have three strings

    a="this is a line"
    b="this is"
    c="a line"
    

    To remove prefix b from a

    echo ${a#"$b"}  # a line
    

    To remove suffix c from a

    echo ${a%"$c"}  # this is
    

提交回复
热议问题