加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash分配默认值

发布时间:2020-12-15 16:38:39 所属栏目:安全 来源:网络整理
导读:${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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读