Up: Creating Subprocesses—In General   [Index]


I.1.1.1 Specifying Shell Arguments

Function: shell-quote-argument argument

This function returns a string that represents, in shell syntax, an argument whose actual contents are ARGUMENT. It should work reliably to concatenate the return value into a shell command and then pass it to a shell for execution. The function is designed to work with the syntax of your system’s standard shell.

Here’s an example of using ‘shell-quote-argument’ to construct a shell command:

(concat "diff -u " (shell-quote-argument oldfile) " " (shell-quote-argument newfile))

Command-Line Argument Processing

The following two functions are useful for combining a list of individual command-line argument strings into a single string, and taking a string apart into a list of individual command-line arguments.

Function: combine-and-quote-strings list-of-strings &optional separator

This function concatenates LIST-OF-STRINGS into a single string, quoting each string as necessary. It also sticks the SEPARATOR string between each pair of strings; if SEPARATOR is omitted or ‘nil’, it defaults to ‘" "’. The return value is the resulting string.

The strings in LIST-OF-STRINGS that need quoting are those that include SEPARATOR as their substring. Quoting a string encloses it in double quotes ‘"…"’. In the simplest case, if you are consing a command from the individual command-line arguments, every argument that includes embedded blanks will be quoted.

Function: split-string-and-unquote string &optional separators

This function splits STRING into substrings at matches for the regular expression SEPARATORS, like ‘split-string’ does. In addition, it removes quoting from the substrings. It then makes a list of the substrings and returns it.


Up: Creating Subprocesses—In General   [Index]