# Quoting command line arguments

When dealing with command line arguments such as the `--classpath` option in different operating systems, proper use of quotes ensures that arguments containing special characters, spaces, or symbols are correctly interpreted. There are various special characters that require special care when used in arguments.

1. **Spaces**: Paths with spaces need to be quoted or escaped.
2. **Asterisks (`*`)**: Must be quoted if intended as a literal; otherwise, they will be interpreted as wildcards.
3. **Commas (`,`)**: Rarely cause issues, but in some contexts, quoting them is safer.
4. **Shell Special Characters**: Characters like `~`, `&`, `|`, `<`, `>`, etc., should be quoted or escaped to prevent the shell from misinterpreting them.
5. **Dollar Signs (`$`)**: Require escaping or quoting, as `$` is used for variable interpolation.

#### Special Characters and Escaping

Each operating system has slightly different conventions for handling arguments with such characters.

**1. Spaces**

* macOS/Linux:
  * Wrap the entire string in **double quotes** or escape spaces with `\` .

    ```
    --classpath="~/My Project/classes:/path/with spaces/file.jar"
    --classpath=~/My\ Project/classes:/path/with\ spaces/file.jar
    ```
* Windows:
  * Wrap the path in **double quotes** to handle spaces.

    ```
    --classpath="C:\My Files\classes;C:\Program Files\path with spaces\file.jar"
    ```

**2. Asterisks (`*`)**

* macOS/Linux:
  * To prevent the shell from expanding the `*` as a wildcard, use quotes or escape it with `\`.

    ```
    --classpath="/path/with/*wildcards"
    --classpath=/path/with/\*wildcards
    ```
* Windows:
  * As Wildcards: No need for quotes; cmd interprets them as wildcards.

    As Literals: Use double quotes to avoid wildcard interpretation.

    ```
    --classpath="C:\path\with\*wildcards"
    ```

**3. Commas (`,`)**

* macOS/Linux:
  * Commas don’t need escaping unless used in contexts where they are interpreted by the shell or program. Quotes are safer in those cases.

    ```
    --classpath="~/path,with,commas/classes"
    ```
* Windows:
  * Generally, commas are not special in cmd, but wrapping the path in double quotes ensures safety.

    ```
    --classpath="C:\path,with,commas\classes;C:\another,path\example.jar"
    ```

**4. `$`, `&`, `<`, `>`, `` ` `` (Backtick)**

* macOS/Linux:
  * Escape with **`\`** or wrap the argument in **single quotes (`'`)** to treat them as literals.

    ```
    --classpath=/path/with/\$dollar\&symbol\file.jar
    --classpath='/path/with/$dollar&symbolfile.jar'
    ```
* Windows:
  * Escape these characters with the **caret (`^`)** or wrap the entire path in **double quotes**.

    ```
    --classpath=C:\path\with^&special\$characters^file.jar
    --classpath="C:\path\with&special\$charactersfile.jar"
    ```

**5. Tilde (`~`)**

* macOS/Linux:
  * The tilde is expanded to the user’s home directory. Escape with `\` or wrap in quotes to prevent expansion.

    ```
    --classpath="\~/MyApp/classes:/path"
    ```
* Windows:
  * The tilde is not expanded as the home directory shortcut in cmd. However, it can be used as part of the path without escaping. For consistency, wrap in quotes if spaces or other special characters are present.

    ```
    --classpath="C:\Users\~username\path\classes"
    ```

**6. Comparison Between macOS/Linux and Windows cmd**

* Below is an example comparing how you would handle `--classpath` in **macOS/Linux** vs. **Windows cmd**.
  * **macOS/Linux Example**

    ```
    --classpath="~/My Files/classes:/path/with\$special\&characters\`file.jar:/path/with/*wildcards"
    ```
  * **Windows Example**

    ```
    --classpath="C:\My Files\classes;C:\path\with^&special\$characters^`file.jar;C:\path\with\*wildcards"
    ```

### Summary of Quoting Rules <a href="#create-generate-upload-reports-bundles" id="create-generate-upload-reports-bundles"></a>

<table data-header-hidden><thead><tr><th width="182"></th><th></th><th width="236"></th></tr></thead><tbody><tr><td><strong>Character</strong></td><td><strong>Linux/macOS (bash/zsh)</strong></td><td><strong>Windows (cmd)</strong></td></tr><tr><td>Spaces</td><td>Double quotes (<code>"</code>) or escape (<code>\</code>)</td><td>Double quotes (<code>"</code>)</td></tr><tr><td>Asterisks (<code>*</code>)</td><td>Double quotes or escape (<code>\</code>)</td><td>Double quotes for literals</td></tr><tr><td>Commas (<code>,</code>)</td><td>Optional quotes</td><td>Optional quotes</td></tr><tr><td><code>$</code>, <code>&#x26;</code>, <code>&#x3C;</code>, <code>></code>, <code>`</code></td><td>Double quotes or escape (<code>\</code>)</td><td>Double quotes or escape (<code>^</code>)</td></tr><tr><td><code>~</code></td><td>Expands to home directory; quote or escape (<code>\</code>)</td><td>No expansion; use quotes for safety</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cover-docs-preview.diffblue.com/features/cover-cli/commands-and-arguments/quoting-command-line-arguments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
