Next: , Previous: , Up: Commands   [Contents][Index]

3.5 Aliases

Aliases are commands that expand to a longer input line. For example, ll is a common alias for ls -l. To define this alias in Eshell, you can use the command invocation alias ll 'ls -l $@*'; with this defined, running ‘ll foo’ in Eshell will actually run ‘ls -l foo’. Aliases defined (or deleted) by the alias command are automatically written to the file named by eshell-aliases-file, which you can also edit directly. After doing so, use M-x eshell-read-aliases-list to load the edited aliases.

Note that unlike aliases in Bash, arguments must be handled explicitly. Within aliases, you can use the special variables ‘$*’, ‘$0’, ‘$1’, ‘$2’, etc. to refer to the arguments passed to the alias.

$*

This expands to the list of arguments passed to the alias. For example, if you run my-alias 1 2 3, then ‘$*’ would be the list (1 2 3). Note that since this variable is a list, using ‘$*’ in an alias will pass this list as a single argument to the aliased command. Therefore, when defining an alias, you should usually use ‘$@*’ to pass all arguments along, splicing them into your argument list (see Dollars Expansion).

$0

This expands to the name of the alias currently being executed.

$1, $2, …, $9

These variables expand to the nth argument (starting at 1) passed to the alias. This lets you selectively use an alias’s arguments, so alias mcd 'mkdir $1 && cd $1' would cause mcd foo to create and switch to a directory called ‘foo’.

Next: Remote Access, Previous: Variables, Up: Commands   [Contents][Index]