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.7 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.8
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:
Concatenate both values together.
Concatenate the string representation of each value, converting back to a number if possible.
nil
) listsConcatenate “adjacent” elements of each value (possibly converting back to a number as above). For example, ‘$(list "a" "b")c’ returns ‘("a" "bc")’.
Concatenate the string representation of each value.