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中,所以不创建一个新的进程。

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...