What is the difference between “var=${var:-word}” and “var=${var:=word}”?

后端 未结 4 1671
北恋
北恋 2020-12-14 03:10

I read the bash man page on this, but I do not understand the difference. I tested both of them out and they seem to produce the exact same results.

I want to set a

4条回答
  •  北海茫月
    2020-12-14 03:30

    You cannot see the difference with your examples as you're using var two times, but you can see it with two different variables:

    foo=${bar:-something}
    
    echo $foo # something
    echo $bar # no assignement to bar, bar is still empty
    
    foo=${bar:=something}
    
    echo $foo # something
    echo $bar # something too, as there's an assignement to bar
    

提交回复
热议问题