以下两种在shell脚本中声明变量的方法有什么区别?
var='some/path'
var=${var:-"some/path"}
答案 0 :(得分:0)
#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"}
答案 1 :(得分:0)
var='some/path'
总是将var设置为some / path
var=${var:-"some/path"}
如果尚未设置var,则仅将var设置为某个/ path。如果已设置,则其值不会更改。