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

### 2.3 Built-in commands

Several commands are built-in in Eshell. In order to call the external variant of a built-in command `foo`, you could call `*foo`. Usually, this should not be necessary. You can check what will be applied by the `which` command:

    ~ $ which ls
    eshell/ls is a compiled Lisp function in `em-ls.el'
    ~ $ which *ls
    /bin/ls

If you want to discard a given built-in command, you could declare an alias, Aliases. Example:

    ~ $ which sudo
    eshell/sudo is a compiled Lisp function in `em-unix.el'
    ~ $ alias sudo '*sudo $*'
    ~ $ which sudo
    sudo is an alias, defined as "*sudo $*"

If you would prefer to use the built-in commands instead of the external commands, set `eshell-prefer-lisp-functions` to `t`.

Some of the built-in commands have different behavior from their external counterparts, and some have no external counterpart. Most of these will print a usage message when given the `--help` option.

`addpath`

  Adds a given path or set of paths to the PATH environment variable, or, with no arguments, prints the current paths in this variable.

`alias`

  Define an alias (see Aliases). This does not add it to the aliases file.

`clear`

  Scrolls the contents of the eshell window out of sight, leaving a blank window. If provided with an optional non-nil argument, the scrollback contents are cleared instead.

`date`

  Similar to, but slightly different from, the GNU Coreutils `date` command.

`define`

  Define a varalias. See Variable Aliases in The Emacs Lisp Reference Manual.

`diff`

  Use Emacs’s internal `diff` (not to be confused with `ediff`). See Comparing Files in The GNU Emacs Manual.

`grep`
`agrep`
`egrep`
`fgrep`
`glimpse`

  The `grep` commands are compatible with GNU `grep`, but use Emacs’s internal `grep` instead.

`info`

  Same as the external `info` command, but uses Emacs’s internal Info reader.

`jobs`

  List subprocesses of the Emacs process, if any, using the function `list-processes`.

`kill`

  Kill processes. Takes a PID or a process object and an optional signal specifier.

`listify`

  Eshell version of `list`. Allows you to create a list using Eshell syntax, rather than Elisp syntax. For example, ‘`listify foo bar`’ and `("foo" "bar")` both evaluate to `("foo" "bar")`.

`locate`

  Alias to Emacs’s `locate` function, which simply runs the external `locate` command and parses the results. See Dired and Find in The GNU Emacs Manual.

`make`

  Run `make` through `compile`. See Compilation in The GNU Emacs Manual.

`occur`

  Alias to Emacs’s `occur`. See Other Repeating Search in The GNU Emacs Manual.

`printnl`

  Print the arguments separated by newlines.

`cd`

  This command changes the current working directory. Usually, it is invoked as ‘`cd foo`’ where `foo` is the new working directory. But `cd` knows about a few special arguments:

  When it receives no argument at all, it changes to the home directory.

  Giving the command ‘`cd -`’ changes back to the previous working directory (this is the same as ‘`cd $-`’).

  The command ‘`cd =`’ shows the directory stack. Each line is numbered.

  With ‘`cd =foo`’, Eshell searches the directory stack for a directory matching the regular expression ‘`foo`’ and changes to that directory.

  With ‘`cd -42`’, you can access the directory stack by number.

`su`
`sudo`

  Uses TRAMP’s `su` or `sudo` method see (tramp)Inline methods to run a command via `su` or `sudo`. These commands are in the eshell-tramp module, which is disabled by default.

#### 2.3.1 Built-in variables

Eshell knows a few built-in variables:

`$+`

  This variable always contains the current working directory.

`$-`

  This variable always contains the previous working directory (the current working directory from before the last `cd` command).

`$_`

  It refers to the last argument of the last command.

`$$`

  This is the result of the last command. In case of an external command, it is `t` or `nil`.

`$?`

  This variable contains the exit code of the last command (0 or 1 for Lisp functions, based on successful completion).

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