Linux shell programming string compare syntax

后端 未结 4 977
小蘑菇
小蘑菇 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:38

    These pages explain the various comparison operators in bash:

    • http://www.tech-recipes.com/rx/209/bournebash-shell-scripts-string-comparison/
    • http://tldp.org/LDP/abs/html/comparison-ops.html
    • http://www.faqs.org/docs/Linux-HOWTO/Bash-Prog-Intro-HOWTO.html#ss11.2

    On the second linked page, you will find:

    ==
    
        is equal to
    
        if [ "$a" == "$b" ]
    
        This is a synonym for =.
    

提交回复
热议问题