1

What's the difference between

failed_instance=`aws deploy`

and

failed_instance=$(aws deploy)

I'm talking about ` and $(?

Pota Onasys
  • 1,302
  • 3
  • 15
  • 18

1 Answers1

5

Both are semantically identical, and both are mandated by the POSIX sh standard, but $() is the newer, modern syntax.

  • Backslash handling is the same as usual inside $(), but backslashes require escaping (lots of escaping if nesting) inside backticks.
  • It nests cleanly. Compare

    printf '%s\n' "$(foo "$(bar)")"     # new POSIX sh syntax
    

    to its old-style equivalent...

    printf '%s\n' "`foo \"\`bar\`\"`"   # legacy Bourne syntax
    
Charles Duffy
  • 257,635
  • 38
  • 339
  • 400