bash中:-(冒号)的用法 [英] Usage of :- (colon dash) in bash

查看:118
本文介绍了bash中:-(冒号)的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

bash中这种样式的含义是什么?

What is the meaning of this style in bash?

${PUBLIC_INTERFACE:-eth0}

:-的目的是什么?

推荐答案

如果$PUBLIC_INTERFACE存在并且不为null,则返回其值,否则返回"eth0".

If $PUBLIC_INTERFACE exists and isn't null, return its value, otherwise return "eth0".

bash手册页中实际上记录了其中的一些:

There are actually a few of these documented in the bash man page:

$ {parameter:-word} 使用默认值.如果参数未设置或为null,则替换单词的扩展名.否则,将替换参数的值.

${parameter:-word} Use Default Values. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.

$ {parameter:= word} 分配默认值.如果参数未设置或为空,则将单词的扩展分配给参数.然后替换参数的值.不能以这种方式分配位置参数和特殊参数.

${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.

$ {parameter:?word} 如果为空或未设置,则显示错误.如果parameter为null或未设置,则将word的扩展名(或如果不存在word则显示一条消息)写入标准错误,并且如果shell不是交互式的,则退出shell.否则,将替换参数的值.

${parameter:?word} Display Error if Null or Unset. If parameter is null or unset, the expansion of word (or a message to that effect if word is not present) is written to the standard error and the shell, if it is not interactive, exits. Otherwise, the value of parameter is substituted.

$ {parameter:+ word} 使用备用值.如果参数为null或未设置,则不替换任何内容,否则替换word的扩展名.

${parameter:+word} Use Alternate Value. If parameter is null or unset, nothing is substituted, otherwise the expansion of word is substituted.

这篇关于bash中:-(冒号)的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆