I'm busy writting shell script (using Bash) where I need to populate some variable from the returned result of other command.

So I'm using a syntax like this one :

VAR=`command 2>/dev/null`

But when looking for information on script shells, I found often that the above can be achieved by using the following syntax too :

VAR=$(command 2>/dev/null)

Both are working for me (I have received the expected result in both case) and I'm thus wondering if I can still use both form interchangeably or if I have to stick to one form to be sure to stay compliant with the future evolution of shell ?


Use dollar. Backticks are semi-deprecated, because they are more complicated to use (see the link), and there are no advantages to them unless you're doing code golf and absolutely need to save a single character. They probably won't be removed from popular shells anytime soon though, so you're safe using either for now.


Stick with the dollar sign notation $() whenever you can. Backticks get cumbersome/confusing when you start needing to do nested quoting. Ex:

$ FOO=`echo "foo's"`
$ echo $FOO

Replacing the backticks with $() yields the same output, and is easier to read (fewer quotes of varrying angles to discern):

$ FOO=$(echo "foo's")
$ echo $FOO

That, and each quotation mark (single quote, double quote, backtick) means something different in the shell, so using $ can help remove a level of complexity. And the developer who follows you will thank you, for he/she will have an easier time figuring out what you did.

  • Backticks cannot even be nested functionally. – Bernhard Jun 24 '14 at 18:29
  • @Bernhard My example shows what I had in-mind with that statement. – Aaron Jun 24 '14 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.