Quoting
Quoting disables a character’s special meaning and allows it to be used literally, as itself. The following characters have special meaning to bash:
|
Character |
Meaning |
|
|
Command separator |
|
|
Background execution |
|
|
Command grouping (enter a subshell) |
|
|
Command block |
|
|
Pipe |
|
|
Redirection symbols |
|
|
Filename metacharacters |
|
|
Used in quoting other characters |
|
|
Command substitution |
|
|
Variable substitution (or command substitution) |
|
newline space tab |
Word separators |
|
|
Comment |
The following characters can be used for quoting:
|
Character |
Action |
|
|
Everything between " and " is taken literally, except for the following characters that keep their special meanings:
|
|
|
Everything between ‘and’ is taken literally, except for another ‘. |
|
|
The character following \ is taken literally. Use within " " to escape “, $, and ‘. Often used to escape itself, spaces, or newlines. |
Examples
$ echo 'Single quotes "protect" double quotes'
Single quotes "protect" double quotes
$ echo "Well, isn't that \"special\"?"
Well, isn't that "special"?
$ echo "You have 'ls | wc -l' files in 'pwd'"
You have 43 files in /home/andy
$ x=100
$ echo "The value of \$x is $x"
The value of $x is 100Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access