Skip to content

Variable expansion

mattirn edited this page Apr 12, 2020 · 3 revisions

Parameter

Positional parameter or the console command-line argument is an entity that store value. It can be a name, a number or a string. A variable is a parameter denoted by a name.

Parameter expansion

The ‘$’ character introduces parameter expansion. The parameter name or symbol to be expanded may be enclosed in braces.

The basic form of parameter expansion is ${parameter}. The value of parameter is substituted. The braces are required when parameter is followed by a character that is not to be interpreted as part of its name.

REPL console

In addition to the console script and command-line argument expansion is done also in command/pipe aliases. In console script alias command must use an alternate character '%' to introduce parameter expansion:

alias xargs '|; %{0} %{1} %{2} %{3} %{4} %{5} %{6} %{7} %{8} %{9}'

${parameter}

Expands to the parameter. When there is no parameter. ${parameter} expand to nothing.

${parameter:-word}

If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.

${@}

Expands to the positional parameters. When there are no positional parameters, ${@} expand to nothing (i.e., they are removed).

Clone this wiki locally