What is the difference between backticks and $() in a Bash script?

BashBackticks

Bash Problem Overview


I see two different forms in Bash scripts which seem to do the same:

`some command`

and

$(some command)

What is the difference between the two, and when should I use each one of them?

Bash Solutions


Solution 1 - Bash

There isn't any semantic difference. The backtick syntax is the older and less powerful version. See man bash, section "Command Substitution".

If your shell supports the $() syntax, prefer it because it can be nested.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMisha MoroshkoView Question on Stackoverflow
Solution 1 - BashthitonView Answer on Stackoverflow