Skip to content
The Bash Insectarium

/static/insetario/en/inseto/param-atribui/

Menu

BSH-005 · Parameters

${var:=padrão}

Like :-, but the default gets written into the variable.

It returns the default when var is empty or absent — and, unlike :-, writes that default into the variable. From the second read on, the value already lives there.

The classic idiom uses the null command: : ${CACHE:=/tmp/ninho} assigns without running anything. Positional and special parameters are excluded — those cannot be written to.

$ unset CACHE
$ : ${CACHE:=/tmp/ninho}
$ echo "$CACHE"
/tmp/ninho
It passed once and left the value planted.