When does command substitution spawn more subshells than the same commands in isolation?

Update and caveat: This answer has a troubled past in that I confidently claimed things that turned out not to be true. I believe it has value in its current form, but please help me eliminate other inaccuracies (or convince me that it should be deleted altogether). I’ve substantially revised – and mostly gutted – … Read more

Backticks vs braces in Bash

The “ is called Command Substitution and is equivalent to $() (parenthesis), while you are using ${} (curly braces). So all of these expressions are equal and mean “interpret the command placed inside”: joulesFinal=`echo $joules2 \* $cpu | bc` joulesFinal=$(echo $joules2 \* $cpu | bc) # v v # ( instead of { v # … Read more

How to address error “bash: !d’: event not found” in Bash command substitution [duplicate]

Bash history expansion is a very odd corner in the bash command line parser, and you are clearly running into an unexpected history expansion, which is explained below. However, any sort of history expansion in a script is unexpected, because normally history expansion is not enabled in scripts; not even scripts run with the source … Read more