Frequently Asked Question
What is command substitution and what's the difference between backticks and $()?
Command substitution captures the output of a command and inserts it into another
command line. There are two syntaxes: the old backtick form `date` and the
modern POSIX form $(date). Both run the inner command and substitute its standard
output (with trailing newlines stripped) into the outer command. Writing
echo "Today is $(date)" produces something like Today is Fri Jan 5 ….
Prefer $()` for almost everything. It nests cleanly, `$(echo $(date)) works,
whereas nested backticks need escaping that quickly becomes unreadable. It is
visually distinct from single quotes, so misreading is harder. It is the POSIX form
and works in every modern shell. Backticks are still seen in older scripts and on
systems where compatibility with very old Bourne shells matters, but for any new
code there is no reason to use them.