Skip to main content

In addition to backticks `command`, command substitution can be done with $(command) or "$(command)", which I find easier to read, and allows for nesting.

OUTPUT=$OUTPUT="$(ls -1)" echo "${OUTPUT}" MULTILINE=$MULTILINE="$(ls \ -1)" echo "${MULTILINE}" 

Quoting (") does matter to preserve multi-line variable values; and it is safer to use with whitespace and special characters such as (*) and therefore advised; it is, however, optional on the right-hand side of an assignment, as when word splitting is not performed, so OUTPUT=$(ls -1) would work fine.

In addition to backticks `command`, command substitution can be done with $(command) or "$(command)", which I find easier to read, and allows for nesting.

OUTPUT=$(ls -1) echo "${OUTPUT}" MULTILINE=$(ls \ -1) echo "${MULTILINE}" 

Quoting (") does matter to preserve multi-line variable values; it is optional on the right-hand side of an assignment, as word splitting is not performed, so OUTPUT=$(ls -1) would work fine.

In addition to backticks `command`, command substitution can be done with $(command) or "$(command)", which I find easier to read, and allows for nesting.

OUTPUT="$(ls -1)" echo "${OUTPUT}" MULTILINE="$(ls \ -1)" echo "${MULTILINE}" 

Quoting (") does matter to preserve multi-line variable values and it is safer to use with whitespace and special characters such as (*) and therefore advised; it is, however, optional on the right-hand side of an assignment when word splitting is not performed, so OUTPUT=$(ls -1) would work fine.

In addition to backticks `command`, command substitution can be done with $(command) or "$(command)", which I find easier to read, and allows for nesting.

OUTPUT="$OUTPUT=$(ls -1)" echo "${OUTPUT}" MULTILINE=$(ls \ -1) echo "${MULTILINE}" 

Quoting (") does matter to preserve multi-line values;multi-line variable values; it is optional on the right-hand side of an assignment, as word splitting is not performed, so OUTPUT=$(ls -1) would work fine.

In addition to backticks `command`, command substitution can be done with $(command) or "$(command)", which I find easier to read, and allows for nesting.

OUTPUT="$(ls -1)" echo "${OUTPUT}" MULTILINE=$(ls \ -1) echo "${MULTILINE}" 

Quoting (") does matter to preserve multi-line values; it is optional on the right-hand side of an assignment, as word splitting is not performed, so OUTPUT=$(ls -1) would work fine.

In addition to backticks `command`, command substitution can be done with $(command) or "$(command)", which I find easier to read, and allows for nesting.

OUTPUT=$(ls -1) echo "${OUTPUT}" MULTILINE=$(ls \ -1) echo "${MULTILINE}" 

Quoting (") does matter to preserve multi-line variable values; it is optional on the right-hand side of an assignment, as word splitting is not performed, so OUTPUT=$(ls -1) would work fine.

Use Markdown instead of HTML for inline backticks; point out that quoting on the RHS of an assignment is optional
Source Link
Benjamin W.
  • 54k
  • 19
  • 135
  • 136

In addition to backticks `command`, command substitution can be done with $(command) or "$(command)", which I find easier to read, and allows for nesting.

OUTPUT="$(ls -1)" echo "${OUTPUT}" MULTILINE=$(ls \ -1) echo "${MULTILINE}" 

Quoting (") does matter to preserve multi-line valuesvalues; it is optional on the right-hand side of an assignment, as word splitting is not performed, so OUTPUT=$(ls -1) would work fine.

In addition to backticks `command`, command substitution can be done with $(command) or "$(command)", which I find easier to read, and allows for nesting.

OUTPUT="$(ls -1)" echo "${OUTPUT}" MULTILINE=$(ls \ -1) echo "${MULTILINE}" 

Quoting (") does matter to preserve multi-line values.

In addition to backticks `command`, command substitution can be done with $(command) or "$(command)", which I find easier to read, and allows for nesting.

OUTPUT="$(ls -1)" echo "${OUTPUT}" MULTILINE=$(ls \ -1) echo "${MULTILINE}" 

Quoting (") does matter to preserve multi-line values; it is optional on the right-hand side of an assignment, as word splitting is not performed, so OUTPUT=$(ls -1) would work fine.

added 106 characters in body
Source Link
John Kugelman
  • 364.5k
  • 70
  • 555
  • 600
Loading
(1) removed English commas which distracted from shell punctuation, (2) more comparable examples of the alternative syntaxes
Source Link
Bob Stein
  • 17.5k
  • 11
  • 92
  • 108
Loading
Adding multiline example.
Source Link
Jonathan
  • 9k
  • 9
  • 56
  • 79
Loading
Quoting does matter.
Source Link
Loading
edited body
Source Link
Marcin Orlowski
  • 75.7k
  • 11
  • 128
  • 152
Loading
Quoted variable
Source Link
that other guy
  • 124.7k
  • 12
  • 187
  • 214
Loading
fix markup
Source Link
Andy Lester
  • 94.2k
  • 16
  • 106
  • 162
Loading
Source Link
Andy Lester
  • 94.2k
  • 16
  • 106
  • 162
Loading