0

In Unix we have 2 ways to execute a command and capture its output in a variable:

1.)

x=`wc-l`

2.)

x=$(wc -l)

Can anyone help me understand the basic difference between the two, and when to use which syntax.

bobbogo
  • 14,989
  • 3
  • 48
  • 57
dev
  • 732
  • 2
  • 8
  • 29
  • see [command substitution in bash manual](https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html#Command-Substitution), back tick is older syntax and parentheses are easier to use with nesting – Nahuel Fouilleul Apr 08 '19 at 08:24
  • https://stackoverflow.com/questions/22709371/backticks-vs-braces-in-bash – gbajson Apr 08 '19 at 08:25
  • Also https://stackoverflow.com/questions/9449778/what-is-the-benefit-of-using-instead-of-backticks-in-shell-scripts – Biffen Apr 08 '19 at 08:26
  • Also: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_03 – dkb Apr 08 '19 at 08:27

0 Answers0