Skip to content
The Bash Insectarium

/static/insetario/en/inseto/param-padrao/

Menu

BSH-004 · Parameters

${var:-padrão}

If the variable is empty, the default takes over — without touching the variable.

The most used operator of parameter expansion: it returns the value of var, or the default when it is empty or does not exist. The variable itself is unchanged.

The colon is the fine aim: ${var-default}, without it, applies the default only when the variable does not exist — empty passes through as empty. The distinction holds for the whole family: :-, :=, :? and :+.

$ unset EDITOR
$ echo "abrindo com ${EDITOR:-nano}"
abrindo com nano
$ EDITOR=vim
$ echo "abrindo com ${EDITOR:-nano}"
abrindo com vim
The default waits quietly until a value is missing.