bash命令与另一结肠结肠开始的等号之前 [英] Bash command starting with colon with another colon before an equals signs
问题描述
我找不到可以解释下面的语法的任何文件。
它是干什么的bash脚本里面呢?它是一个测试?
:$ {foo的:=巴};出口富
的:
命令是的空实用:
这个工具只expand命令参数。如果在命令的当时的条件是需要一个命令时,它被用来作为,但没有什么是被命令来完成。
块引用>
什么也不做超出扩大参数和执行重定向。返回状态是零。
块引用>的
$ {foo的:=巴}
语法是一个特殊的<一个href=\"http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02\">Parameter扩展:$ {参数:= [文字]}
指定缺省值。如果参数没有设置或者为空,word的扩展(或者如果省略字空字符串),应分配给参数。在所有的情况下,参数的最终值应被取代的。只有变量,位置不是固定的参数或特殊参数,可以以这种方式进行分配。
块引用>猛砸参考手册进入:
$ {参数:=词}
如果参数没有设置或者为空,word的扩展被分配到参数。参数的值,然后被取代。位置参数和特别参数可能不以这种方式被分配给
块引用>所以你的问题的命令行:
:$ {foo的:=巴};出口富
时的两个命令:
:$ {foo的:=巴}
出口富
第一,其中扩展变量
富
,如果它是空的或取消其分配值栏
。其中的第二个出口,然后在
富
变量子壳等过程。I could not find any documentation that would explain the syntax below. What does it do inside a bash script? Is it a test?
: ${foo:=bar}; export foo
解决方案The
:
command is the null utility:This utility shall only expand command arguments. It is used when a command is needed, as in the then condition of an if command, but nothing is to be done by the command.
Also Bourne Shell Builtins:
Do nothing beyond expanding arguments and performing redirections. The return status is zero.
The
${foo:=bar}
syntax is a special Parameter Expansion:${parameter:=[word]}
Assign Default Values. If parameter is unset or null, the expansion of word (or an empty string if word is omitted) shall be assigned to parameter. In all cases, the final value of parameter shall be substituted. Only variables, not positional parameters or special parameters, can be assigned in this way.
Bash Reference manual entry:
${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.
So the command line in your question:
: ${foo:=bar}; export foo
Is two commands:
: ${foo:=bar}
export foo
The first of which expands the variable
foo
and if it is empty or unset assigns it the valuebar
.The second of which then exports the
foo
variable for sub-shells and other processes.这篇关于bash命令与另一结肠结肠开始的等号之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!