String difference in Bash

后端 未结 5 908
借酒劲吻你
借酒劲吻你 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:21

    I prefer cmp and Process Substitution feature of bash:

    $ cmp -bl <(echo -n abcda) <(echo -n aqcde)
      2 142 b    161 q
      5 141 a    145 e
    

    Saying on position 2, a b occurs for the first, but a q for the second. At position 5, another difference is happening. Just replace those strings by variables, and you are done.

提交回复
热议问题