$ {ARGUMENT + x}在Bash中是什么意思? [英] What does ${ARGUMENT+x} mean in Bash?

查看:123
本文介绍了$ {ARGUMENT + x}在Bash中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用以下语法的bash脚本:

I have a bash script that uses the following syntax:

if [ ! -z ${ARGUMENT+x} ]; then

参数名称后面的"+ x"语法是什么意思?

What is the meaning of the "+x" syntax after the argument name?

推荐答案

这意味着如果设置了$ARGUMENT,它将被字符串x

It means that if $ARGUMENT is set, it will be replaced by the string x

$ echo  ${ARGUMENT+x}

$ ARGUMENT=123
$ echo  ${ARGUMENT+x}
x

您也可以使用此表单编写此内容:

You can write this with this form too :

${ARGUMENT:+x}

:中有特殊含义,它测试变量未设置

It have a special meaning with :, it test that variable is empty or unset

检查 bash 参数扩展

这篇关于$ {ARGUMENT + x}在Bash中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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