Bash command substitution

Date: 2020-04-03

https://stackoverflow.com/a/22709390

he `` is called Command Substitution and is equivalent to $() (parenthesis), while you are using ${} (curly braces).

So these are equal and mean “interpret the command placed inside”:

joulesFinal=`echo $joules2 \* $cpu | bc`
joulesFinal=$(echo $joules2 \* $cpu | bc)
             ^                          ^
       ( instead of {             ) instead of }

While ${} expressions are used for variable substitution.


From man bash:

Command substitution allows the output of a command to replace the command name. There are two forms:

          $(command)
   or
          `command`

Also, `` are more difficult to handle, you cannot nest them for example. See comments below and also Why is $(…) preferred over ... (backticks)?.

backtics are deprecated and $() is POSIX compatible

36500cookie-checkBash command substitution