Linux shell programming string compare syntax

后端 未结 4 987
小蘑菇
小蘑菇 2021-02-12 18:47

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

Maybe the following code works:

if [ \"$         


        
4条回答
  •  南旧
    南旧 (楼主)
    2021-02-12 19:26

    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

提交回复
热议问题