Linux shell programming string compare syntax

后端 未结 4 1292
南方客
南方客 2021-02-12 19:07

What is the difference between = and == to compare strings in Linux shell programming?

Maybe the following code works:

if [ \"$         


        
4条回答
  •  不知归路
    2021-02-12 19:45

    you can take a look here or here. Personally, to compare strings, I use case

    case "$string1" in
      "$string2" ) echo "matched";;
      *) echo "not matched";;
    esac
    

    I do not have to know which operator i should use

提交回复
热议问题