Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Bash, quotes control how the shell interprets text: single quotes make enclosed characters literal, while double quotes preserve an expansion as one argument but still allow variables and commands to expand. Most quoting problems come from forgetting that unquoted expansion results can be split into words or expanded as filename patterns.

What quoting does in Bash

Quoting changes shell syntax. The GNU Bash Reference Manual describes quoting as removing the special meaning of certain characters or words to the shell. Bash documents four mechanisms: backslash escaping, single quotes, double quotes, and dollar-single quotes. See the Bash manual’s Quoting section.

The examples below name Bash because “Linux” does not identify one shell. Other shells may parse some quoting forms differently.

Single quotes versus double quotes

Form What it does Example Use it when
Single quotes: '...' Preserves the literal value of every enclosed character. '$HOME *.txt' passes the dollar sign and asterisk as ordinary characters. You need fixed text with spaces or shell metacharacters.
Double quotes: "..." Preserves the argument boundary, while still allowing variable and command substitution. Some backslashes and backquotes retain special meaning. "$HOME" expands the variable but keeps its result in one argument. You want an expansion but need it treated as one argument.

Bash documents that single quotes preserve each character’s literal value, but a single quote cannot appear directly inside a single-quoted string. Double quotes protect most characters, but $, backquotes, and backslashes in selected cases remain significant; ! can also be special when history expansion is enabled. Details are in the manual’s Single Quotes and Double Quotes sections.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why an unquoted variable can split into several arguments

Consider a variable containing quarterly report.txt. In a command such as printf '<%s>n' $value, the unquoted expansion can undergo word splitting, producing separate arguments. If the value includes wildcard characters such as *, filename expansion can also match files in the current directory.

Quoting the expansion as "$value" prevents those usual splitting and pathname-expansion effects, so the value remains one argument. This is why double quotes are generally the right choice around variable expansions when a single argument is intended.

The order matters: Bash performs parameter and command expansion, then word splitting and filename expansion, and finally quote removal. Quote removal does not undo the earlier effects of an unquoted expansion. The full sequence is documented in the Bash manual’s Shell Expansions section.

How to include an apostrophe in text

A single quote cannot be placed directly inside a single-quoted string. To pass don't as one literal argument, close the single-quoted portion, add the apostrophe in another quote context, and reopen the literal portion:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

'don'"'"'t'

The adjacent pieces are joined by the shell into one word; the quote characters used to describe those pieces are not passed as part of the argument. For a single isolated special character, a backslash can be simpler, but backslash behavior depends on whether it appears inside or outside quotes.

Which quoting form should you choose?

  • Fixed text with spaces or metacharacters: use single quotes unless the text itself contains an apostrophe.
  • A variable or command substitution that must stay one argument: put it inside double quotes, such as "$value" or "$(command)".
  • One isolated metacharacter: use a backslash escape when its context makes that clear.
  • C-style escapes such as a newline or tab in Bash: use dollar-single quotes, for example $'line onenline two'. This form is Bash-specific; check the target shell before relying on it.

Do Linux shells all handle quotes the same way?

No. Bash, POSIX-compatible shells, zsh, and csh are not interchangeable in every quoting detail. Dollar-single quotes and Bash history-expansion behavior are examples of features that may be absent or behave differently elsewhere. GNU Coreutils cautions that its shell-quoting styles suit POSIX-compatible shells such as Bash but may not work for incompatible shells such as csh; see the Coreutils manual’s Quoting section. When writing commands or scripts, name the shell you intend to use rather than assuming every Linux shell interprets the same syntax.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why a command may print quotes around a filename

Quotes shown in output are not necessarily quote characters in the filename. A tool may display a shell-usable representation to make spaces or special characters clear. GNU Coreutils documents quoting styles including shell, shell-always, shell-escape, and shell-escape-always; their availability and behavior belong to the tool, not to Bash’s input-parsing rules.

In particular, GNU Coreutils says ls began quoting filenames containing special characters by default in coreutils 8.25, released in January 2016. That change affected how ls displayed names; it did not change how Bash parses quotes you type.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.