bash分配默认值

前端之家收集整理的这篇文章主要介绍了bash分配默认值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

${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:= hello},而不是更长的LONG_VARIABLE_NAME = $ {LONG_VARIABLE_NAME:-hello},但现在bash也尝试执行“hello”,并给出一个命令未找到。任何方式,以避免?还是我会坚持后者?有人可以给一个例子,其中的赋值默认实际上是有用的?

使用冒号:
: ${A:=hello}

冒号是一个空命令,不执行任何操作,忽略其参数。它被内置到bash中,所以不创建一个新的进程。

原文链接:https://www.f2er.com/bash/391843.html

猜你在找的Bash相关文章