&是什么QUOT;加上冒号" (`+:`)意味着shell脚本前pressions?

编程入门 行业动态 更新时间:2024-10-28 17:24:40
本文介绍了&是什么QUOT;加上冒号" (`+:`)意味着shell脚本前pressions?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是什么意思:

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?

本文发布于:2023-06-07 03:52:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/560841.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:冒号   脚本   QUOT   pressions   shell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!