Next: transform, Previous: wildcards, Up: Choosing [Contents][Index]

### 6.6 Quoting Member Names

When displaying member names, `tar` takes care to avoid ambiguities caused by certain characters. This is called name quoting. The characters in question are:

- Non-printable control characters:

  Character | ASCII | Character name
  --- | --- | ---
  \a | 7 | Audible bell
  \b | 8 | Backspace
  \f | 12 | Form feed
  \n | 10 | New line
  \r | 13 | Carriage return
  \t | 9 | Horizontal tabulation
  \v | 11 | Vertical tabulation

- Space (ASCII 32)
- Single and double quotes (‘`'`’ and ‘`"`’)
- Backslash (‘`\`’)

The exact way `tar` uses to quote these characters depends on the quoting style. The default quoting style, called escape (see below), uses backslash notation to represent control characters, space and backslash. Using this quoting style, control characters are represented as listed in column ‘`Character`’ in the above table, a space is printed as ‘`\` ’ and a backslash as ‘`\\`’.

GNU `tar` offers seven distinct quoting styles, which can be selected using `--quoting-style` option:

`--quoting-style=style`

  Sets quoting style. Valid values for style argument are: literal, shell, shell-always, c, escape, locale, clocale.

These styles are described in detail below. To illustrate their effect, we will use an imaginary tar archive `arch.tar` containing the following members:

    # 1. Contains horizontal tabulation character.
    a       tab
    # 2. Contains newline character
    a
    newline
    # 3. Contains a space
    a space
    # 4. Contains double quotes
    a"double"quote
    # 5. Contains single quotes
    a'single'quote
    # 6. Contains a backslash character:
    a\backslash

Here is how usual `ls` command would have listed them, if they had existed in the current working directory:

    $ ls
    a\ttab
    a\nnewline
    a\ space
    a"double"quote
    a'single'quote
    a\\backslash

Quoting styles:

‘`literal`’

  No quoting, display each character as is:

      $ tar tf arch.tar --quoting-style=literal
      ./
      ./a space
      ./a'single'quote
      ./a"double"quote
      ./a\backslash
      ./a     tab
      ./a
      newline

‘`shell`’

  Display characters the same way Bourne shell does: control characters, except ‘`\t`’ and ‘`\n`’, are printed using backslash escapes, ‘`\t`’ and ‘`\n`’ are printed as is, and a single quote is printed as ‘`\'`’. If a name contains any quoted characters, it is enclosed in single quotes. In particular, if a name contains single quotes, it is printed as several single-quoted strings:

      $ tar tf arch.tar --quoting-style=shell
      ./
      './a space'
      './a'\''single'\''quote'
      './a"double"quote'
      './a\backslash'
      './a    tab'
      './a
      newline'

‘`shell-always`’

  Same as ‘`shell`’, but the names are always enclosed in single quotes:

      $ tar tf arch.tar --quoting-style=shell-always
      './'
      './a space'
      './a'\''single'\''quote'
      './a"double"quote'
      './a\backslash'
      './a    tab'
      './a
      newline'

‘`c`’

  Use the notation of the C programming language. All names are enclosed in double quotes. Control characters are quoted using backslash notations, double quotes are represented as ‘`\"`’, backslash characters are represented as ‘`\\`’. Single quotes and spaces are not quoted:

      $ tar tf arch.tar --quoting-style=c
      "./"
      "./a space"
      "./a'single'quote"
      "./a\"double\"quote"
      "./a\\backslash"
      "./a\ttab"
      "./a\nnewline"

‘`escape`’

  Control characters are printed using backslash notation, a space is printed as ‘`\` ’ and a backslash as ‘`\\`’. This is the default quoting style, unless it was changed when configured the package.

      $ tar tf arch.tar --quoting-style=escape
      ./
      ./a space
      ./a'single'quote
      ./a"double"quote
      ./a\\backslash
      ./a\ttab
      ./a\nnewline

‘`locale`’

  Control characters, single quote and backslash are printed using backslash notation. All names are quoted using left and right quotation marks, appropriate to the current locale. If it does not define quotation marks, use ‘`'`’ as left and as right quotation marks. Any occurrences of the right quotation mark in a name are escaped with ‘`\`’, for example:

  For example:

      $ tar tf arch.tar --quoting-style=locale
      './'
      './a space'
      './a\'single\'quote'
      './a"double"quote'
      './a\\backslash'
      './a\ttab'
      './a\nnewline'

‘`clocale`’

  Same as ‘`locale`’, but ‘`"`’ is used for both left and right quotation marks, if not provided by the currently selected locale:

      $ tar tf arch.tar --quoting-style=clocale
      "./"
      "./a space"
      "./a'single'quote"
      "./a\"double\"quote"
      "./a\\backslash"
      "./a\ttab"
      "./a\nnewline"

You can specify which characters should be quoted in addition to those implied by the current quoting style:

`--quote-chars=string`

  Always quote characters from string, even if the selected quoting style would not quote them.

For example, using ‘`escape`’ quoting (compare with the usual escape listing above):

    $ tar tf arch.tar --quoting-style=escape --quote-chars=' "'
    ./
    ./a\ space
    ./a'single'quote
    ./a\"double\"quote
    ./a\\backslash
    ./a\ttab
    ./a\nnewline

To disable quoting of such additional characters, use the following option:

`--no-quote-chars=string`

  Remove characters listed in string from the list of quoted characters set by the previous `--quote-chars` option.

This option is particularly useful if you have added `--quote-chars` to your `TAR_OPTIONS` (see TAR_OPTIONS) and wish to disable it for the current invocation.

Note, that `--no-quote-chars` does not disable those characters that are quoted by default in the selected quoting style.

Next: transform, Previous: wildcards, Up: Choosing [Contents][Index]