Skip to main content
10 of 12
Use Markdown instead of HTML for inline backticks; point out that quoting on the RHS of an assignment is optional
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 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.

Andy Lester
  • 94.2k
  • 16
  • 106
  • 162