Skip to content

Expansion

Expansion in a command shell is somewhat like macro expansion in macro parsers (such as cpp and m4), but in a command shell, they are less often used for constants, and usually for using variables and string manipulation.[1] For example, $var on a line expands to the value of the variable var when the line is executed. Expansions are usually passed as arguments, but may also be used as commands.[2]

You can concatenate expansions with regular string arguments or even other expansions. In the simplest case, when the expansion returns a string value, this is equivalent to ordinary string concatenation; for example, ‘${echo "foo"}bar’ returns ‘foobar’. The exact behavior depends on the types of each value being concatenated:

both strings

Concatenate both values together.

one or both numbers

Concatenate the string representation of each value, converting back to a number if possible.

one or both (non-nil) lists

Concatenate “adjacent” elements of each value (possibly converting back to a number as above). For example, ‘$(list "a" "b")c’ returns ‘("a" "bc")’.

anything else

Concatenate the string representation of each value.


  1. Eshell has no string-manipulation expansions because the Elisp library already provides many functions for this. ↩︎

  2. E.g., entering just ‘$var’ at the prompt is equivalent to entering the value of var at the prompt. ↩︎