庆典指定默认值

编程入门 行业动态 更新时间:2024-10-08 20:29:40
本文介绍了庆典指定默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

$ {参数:=词}                指定的默认​​值。如果参数没有设置或者为空,则  字的扩张被分配给  参数。参数的值是  然后取代。阵地  参数和特殊                参数可能不以这种方式被分配给

${parameter:=word} 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.

我想我可以使用这个功能来写 $ {LONG_VARIABLE_NAME:=你好} 而不是较长的 LONG_VARIABLE_NAME = $ {LONG_VARIABLE_NAME:-Hello } ,但现在的bash也试图执行'你好'这给了未找到命令。任何方式避免这种情况?或将我必须坚持后者?有人可以举一个例子,其中指定默认实际上是有用的?

I thought I could use this feature to write ${LONG_VARIABLE_NAME:=hello} instead of the longer LONG_VARIABLE_NAME=${LONG_VARIABLE_NAME:-hello}, but now bash also tries to execute 'hello' and that gives a command not found. Any way to avoid that? Or will I have to stick to the latter? Can someone give an example where the assign default is actually useful?

推荐答案

使用冒号:

: ${A:=hello}

结肠是空指令,什么也不做,而忽略它的参数。它内置的bash所以不会创建一个新的进程。

The colon is a null command that does nothing and ignores its arguments. It is built into bash so a new process is not created.

更多推荐

庆典指定默认值

本文发布于:2023-10-16 13:56:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:庆典   默认值

发布评论

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

>www.elefans.com

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