以下两种在shell脚本中声明变量的方法有什么区别?
var='some/path'
var=${var:-"some/path"}
var='some/path'
总是将 var 设置为 some/path
var=${var:-"some/path"}
如果 var 尚未设置,则只会将 var 设置为 some/path。如果它被设置,它的值不会改变。
#this will set var value with some/path,
#no matter var is empty or not (overwrite)
var='some/path'
# this will set value of var to "some/path"
#only if var is empty/or not declared yet.
var=${var:-"some/path"}