Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. single quoting (e.g. 'some text') – this serves two purposes
    • it groups together all text inside the quotes into a single token
    • it tells the shell not to "look inside" the quotes to perform any evaluation
      • all metacharacters inside the single quotes are ignored
      • in particular, any environment variables in single-quoted text are not evaluated
  2. double quoting (e.g. "some text") – also serves two purposes
    • it groups together all text inside the quotes into a single token
    • it allows environment variable evaluation, but inhibits some metacharcters
      • e.g. asterisk ( * ) pathname globbing (more on globbing later...)
      • and some other metacharacters
    • double quoting also preserves any special characters in the text
      • e.g. newlines (\n) or Tabs (\t)
  3. backtick quoting (e.g. `date`)
    • evaluates the expression inside the backtick marks ( ` )
    • the standard output of the expression replaces the text inside the backtick marks ( ` )

Note that the quote characters themselves ( '  "  ` ) are metacharacters that tell the shell to "start a quoting process" then "end a quoting process" when the matching quote is found. Since they are part of the processing, the enclosing quotes are not included in the output.

Let's look at examples of these.

...

Code Block
languagebash
FOO="Hello world!"
echo "The value of variable 'FOO' is \"$FOO\""   # Escape the double quotes inside double quotes
echo "The value of variable 'FOO' is "'"'$FOO'"'   # Single-quoted text after double-quoted text

...

Tip

If you see the greater than ( > ) character after pressing Enter, it can mean that your quotes are not paired, and the shell is waiting for more input to contain the missing quote of the pair (either single or double). Just use Ctrl-c to get back to the prompt.

Note that the quote characters themselves ( '  "  ` ) are metacharacters that tell the shell to "start a quoting process" then "end a quoting process" when the matching quote is found. Since they are part of the processing, the enclosing quotes are not included in the output.

Exercise 3-3

How would you output this text: The backslash character \ is used for escaping

...