Linux shell programming string compare syntax

后端 未结 4 1296
南方客
南方客 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:31

    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 =.
    

提交回复
热议问题