Why is $(...) preferred over `...` (backticks)?

The `cmd` backtick format is the legacy syntax for command substitution, required only by more than 30-year-old Bourne shells. The modern POSIX $(...) syntax is preferred for many reasons:

Important differences

   1 $ echo "`echo \\a`"
   2 a
   3 $ echo "`echo \\\\a`"
   4 \a 
   5 $ echo "$(echo \\a)"
   6 \\a
   7 
   8 # Note that this is true
   9 # for *single quotes* too!
  10 $ str=`echo '\\'`
  11 $ echo "str is $str"
  12 str is \
  13 $ str=$(echo '\\')
  14 $ echo "str is $str"
  15 str is \\

Other advantages

See also: