Skip to content
The Bash Insectarium

/static/insetario/en/inseto/param-alterno/

Menu

BSH-007 · Parameters

${var:+alterno}

The default's opposite: it only produces a value when the variable has one.

The mirror of :-: when var has a value, the expansion returns the alternate; when it is empty or absent, it returns nothing. The variable's own value never shows up.

It is for switching pieces of a command line on and off: ${VERBOSO:+--verbose} injects the option only when the variable is set. The whole flag lives or dies with the variable.

$ VERBOSO=1
$ ./coletar.sh ${VERBOSO:+--verbose}
coletando (modo verboso)
$ unset VERBOSO
$ ./coletar.sh ${VERBOSO:+--verbose}
coletando
The option appears only when summoned.