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


3.2 Arguments

When calling external commands (and many built-in Eshell commands, too) Eshell will flatten the arguments the command receives, so passing a list as an argument will “spread” the elements into multiple arguments:

~ $ printnl (list 1 2) 3
1
2
3

3.2.1 Quoting and Escaping

As with other shells, you can escape special characters and spaces by prefixing the character with a backslash (‘\’), or by surrounding the string with apostrophes (‘''’) or double quotes (‘""’). This is needed especially for file names with special characters like pipe (‘|’) or square brackets (‘[’ or ‘]’), which could be part of remote file names. In addition, quoting or escaping an argument will prevent it from being converted to a number when passed to a Lisp function.

When you escape a character with ‘\’ outside of any quotes, the result is the literal character immediately following it. For example, \10ドル means the literal string 10ドル.

Inside of double quotes, most characters have no special meaning. However, ‘\’, ‘"’, and ‘$’ are still special; to escape them, use backslash as above. Thus, if the value of the variable answer is 42, then "The answer is: \"$answer\"" returns the string The answer is: "42". However, when escaping characters with no special meaning, the result is the full \c sequence. For example, "foo\bar" means the literal string foo\bar.

Additionally, when escaping a newline, the whole escape sequence is removed by the parser. This lets you continue commands across multiple lines:

~ $ echo "foo\
bar"
foobar

Inside apostrophes, escaping works differently. All characters between the apostrophes have their literal meaning except ‘'’, which ends the quoted string. To insert a literal apostrophe, you can use ‘''’, so 'It''s me' means the literal string It's me.

When using expansions (see Expansion) in an Eshell command, the result may potentially be of any data type. To ensure that the result is always a string, the expansion can be surrounded by double quotes.

3.2.2 Type Conversion

When invoking a Lisp function via command form, Eshell automatically converts string arguments that look like numbers to actual Lisp numbers in order to make it easier to work with numeric values. You can prevent this conversion on a case-by-case basis by quoting or escaping the argument:

~ $ type-of 1
integer
~ $ type-of "1"
string

When invoking a subcommand in command form, Eshell will split the output line-by-line into a list. Additionally, if every line looks like a number, then Eshell will mark them as numeric so that passing them to a Lisp function will convert them to Lisp numbers:

~ $ cat numbers.txt
01
02
03
~ $ + $@{cat numbers.txt}
6

If you find this behavior inconvenient for certain functions, you can tell Eshell not to perform this conversion for that function:

(put \\='find-file \\='eshell-no-numeric-conversions t)

You can also disable this conversion behavior entirely by setting eshell-convert-numeric-arguments to nil.

3.2.3 Special Argument Types

In addition to strings and numbers, Eshell supports a number of special argument types. These let you refer to various other Emacs Lisp data types, such as lists or buffers.

#'lisp-form

This refers to the quoted Emacs Lisp form lisp-form. Though this looks similar to the “sharp quote” syntax for functions (see Special Read Syntax in The Emacs Lisp Reference Manual), it instead corresponds to quote and can be used for any quoted form.5

`lisp-form

This refers to the backquoted Emacs Lisp form lisp-form (see Backquote in The Emacs Lisp Reference Manual). As in Emacs Lisp, you can use ‘,’ and ‘,@’ to refer to non-constant values.

#<buffer name>
#<name>

Return the buffer named name. This is equivalent to ‘$(get-buffer-create "name")’ (see Creating Buffers in The Emacs Lisp Reference Manual).

#<marker position buffer-or-name>

Return a marker at position in the buffer buffer-or-name. buffer-or-name can either be a string naming a buffer or an actual buffer object. This is roughly equivalent to creating a new marker and calling ‘$(set-marker marker position buffer-or-name)’ (see Moving Markers in The Emacs Lisp Reference Manual).

#<process name>

Return the process named name. This is equivalent to ‘$(get-process "name")’ (see Process Information in The Emacs Lisp Reference Manual).


Footnotes

(5)

Eshell would interpret a bare apostrophe (') as the start of a single-quoted string.


Next: Built-in Commands, Previous: Invocation, Up: Commands [Contents][Index]

AltStyle によって変換されたページ (->オリジナル) /