What is the difference between `$(command)` and backticks?
BeginnerConceptShells, scripts and execution
Answer
Both are command substitution: run the command and substitute its stdout, with trailing newlines removed. $( ) nests cleanly and handles backslashes predictably; backticks need escaping to nest and are hard to read.
release=$(basename "$(readlink -f /srv/app/current)")
Always use $( ) and quote it: "$(cmd)".
More on Shells, scripts and execution
What is a shell, and how is Bash different from sh, dash and zsh?BeginnerWhat does the shebang line do, and why prefer `#!/usr/bin/env bash` over `#!/bin/bash`?BeginnerWhat is the difference between `./script.sh`, `bash script.sh` and `source script.sh`?BeginnerWhat happens when you type a command name? How does Bash decide what to run?AdvancedWhy must `cd`, `export` and `read` be builtins rather than external programs?IntermediateWhat is the difference between a login, interactive and non-interactive shell, and which startup files run?Intermediate