Bash 脚本 := 是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1064280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash script what is := for?
提问by freshWoWer
Does anyone know what is := for?
有谁知道 := 是什么?
I tried googling but it seems google filters all symbol?
我试过谷歌搜索,但似乎谷歌过滤了所有符号?
I know the below is something like checking if the variable HOME is a directory and then something is not equal to empty string.
我知道下面的内容类似于检查变量 HOME 是否是目录,然后某些内容不等于空字符串。
if [ "${HOME:=}" != "" ] && [ -d ${HOME} ]
回答by Andrew Hare
From Bash Reference Manual:
来自Bash 参考手册:
${parameter:=word}If parameter is unset or null, the expansion of word is assigned to parameter. The value of parameter is then substituted. Positional parameters and special parameters may not be assigned to in this way.
${parameter:=word}如果参数未设置或为空,则将单词的扩展分配给参数。然后替换参数的值。不能以这种方式分配位置参数和特殊参数。
Basically it will assign the value of wordto parameterif and only if parameteris unset or null.
基本上word,parameter当且仅当parameter未设置或为空时,它才会将值分配给。
回答by mipadi
From the Bash man page:
从 Bash 手册页:
Assign Default Values. If parameter is unset or null, the expansion of word is assigned to parameter. The value of parameter is then substituted. Positional parameters and special parameters may not be assigned to in this way.
分配默认值。如果参数未设置或为空,则将单词的扩展分配给参数。然后替换参数的值。不能以这种方式分配位置参数和特殊参数。
Man pages are a wonderful thing. man bashwill tell you almost everything you want to know about Bash.
手册页是一件美妙的事情。man bash将告诉您几乎所有您想了解的有关 Bash 的信息。

