Next: , Up: Expansion   [Contents][Index]

3.1 Dollars Expansion

Eshell has different $ expansion syntax from other shells. There are some similarities, but don’t let these lull you into a false sense of familiarity.

$var

Expands to the value bound to var. This is the main way to use variables in command invocations.

$"var"
$'var'

Expands to the value bound to var. This is useful to disambiguate the variable name when concatenating it with another value, such as ‘$"var"-suffix’.

$#var

Expands to the length of the value bound to var. Raises an error if the value is not a sequence (see Sequences in The Emacs Lisp Reference Manual).

$(lisp)

Expands to the result of evaluating the S-expression (lisp). On its own, this is identical to just (lisp), but with the $, it can be used in a string, such as ‘/some/path/$(lisp).txt’.

${command}

Returns the output of command, which can be any valid Eshell command invocation, and may even contain expansions.

$<command>

As with ‘${command}’, evaluates the Eshell command invocation command, but writes the output to a temporary file and returns the file name.

$var[i]

Expands to the ith element of the value bound to var. If the value is a string, it will be split at whitespace to make it a list. Again, raises an error if the value is not a sequence.

$var[: i]

As above, but now splitting occurs at the colon character.

$var[: i j]

As above, but instead of returning just a string, it now returns a list of two strings. If the result is being interpolated into a larger string, this list will be flattened into one big string, with each element separated by a space.

$var["\\\\" i]

Separate on backslash characters. Actually, the first argument – if it doesn’t have the form of a number, or a plain variable name – can be any regular expression. So to split on numbers, use ‘$var["[0-9]+" 10 20]’.

$var[hello]

Calls assoc on var with "hello", expecting it to be an alist (see Association Lists in The Emacs Lisp Reference Manual).

$#var[hello]

Returns the length of the cdr of the element of var whose car is equal to "hello".

Next: , Up: Expansion   [Contents][Index]