&是什么QUOT;加上冒号" (`+:`)意味着shell脚本前pressions? [英] What does "plus colon" (`+:`) mean in shell script expressions?
问题描述
这是什么意思:
if ${ac_cv_lib_lept_pixCreate+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
看起来 ac_cv_lib_lept_pixCreate
一些变量,所以什么是+?意味着
Looks like ac_cv_lib_lept_pixCreate
is some variable, so what does "+:" mean?
在哪里学习的花括号前pressions的完整语法?这是什么语法的名字?
Where to learn complete syntax of curly bracket expressions? What is the name of this syntax?
推荐答案
在加冒号 $ {... +:}
前pression,只有 +
在外壳特殊的意义。冒号就是在这种情况下,一个字符串值,这样我们就可以编写代码段为 $ {... +:}
In the "plus colon" ${...+:}
expression, only the +
has special meaning in the shell. The colon is just a string value in this case, so we could write that snippet as ${...+":"}
.
为了方便起见,我们pretend的变量称为 VAR
,并考虑除权pression:
For convenience, let's pretend the variable is called var
, and consider the expression:
if ${var+:} false; then ...
如果shell变量 $ VAR
存在,整个前pression被替换:
,如果不,它返回一个空字符串。
If the shell variable $var
exists, the entire expression is replaced with :
, if not, it returns an empty string.
因此整个前pression $ {VAR +:}虚假
变为::假
(返回true )或假
(返回false)。
Therefore the entire expression ${var+:} false
becomes either : false
(returning true) or false
(returning false).
这归结为生存的考验,它可以是即使变量没有赋值真。
This comes down to a test for existence, which can be true even if the variable has no value assigned.
这是非常神秘的,可是事实上,是实际工作中大多数变量存在的几个测试之一,如果不是全部,伯恩血统炮弹。
It is very cryptic, but as it happens, is one of the few tests for the existence of a variable that actually works in most, if not all, shells of Bourne descent.
可能等同于:(此处替换任何变量名称为 VAR
)
Possible equivalents: (substitute any variable name here for var
)
if [[ ${var+"is_set"} == is_set ]]; then ...
或者,可能更便于携带:
Or, probably more portable:
case ${var+"IS_SET"} in IS_SET) ...;; esac
这篇关于&是什么QUOT;加上冒号" (`+:`)意味着shell脚本前pressions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!