{"id":3650,"date":"2020-04-03T21:43:49","date_gmt":"2020-04-03T20:43:49","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=3650"},"modified":"2020-04-21T17:03:28","modified_gmt":"2020-04-21T16:03:28","slug":"bash-command-substitution","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/bash-command-substitution\/","title":{"rendered":"Bash command substitution"},"content":{"rendered":"\n<p><a href=\"https:\/\/stackoverflow.com\/a\/22709390\">https:\/\/stackoverflow.com\/a\/22709390<\/a><\/p>\n\n\n\n<p>he&nbsp;<code>``<\/code>&nbsp;is called Command Substitution and is equivalent to&nbsp;<code>$()<\/code>&nbsp;(parenthesis), while you are using&nbsp;<code>${}<\/code>&nbsp;(curly braces).<\/p>\n\n\n\n<p>So these are equal and mean &#8220;interpret the command placed inside&#8221;:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">joulesFinal=`echo $joules2 \\* $cpu | bc`\njoulesFinal=$(echo $joules2 \\* $cpu | bc)\n             ^                          ^\n       ( instead of {             ) instead of }<\/pre>\n\n\n\n<p>While&nbsp;<code>${}<\/code>&nbsp;expressions are used for variable substitution.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>From&nbsp;<code>man bash<\/code>:<\/p>\n\n\n\n<p><strong>Command substitution<\/strong>&nbsp;allows the output of a command to replace the command name. There are two forms:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">          $(command)\n   or\n          `command`<\/pre>\n\n\n\n<p>Also,&nbsp;<code>``<\/code>&nbsp;are more difficult to handle, you cannot nest them for example. See comments below and also&nbsp;<a href=\"http:\/\/mywiki.wooledge.org\/BashFAQ\/082\">Why is $(&#8230;) preferred over&nbsp;<code>...<\/code>&nbsp;(backticks)?<\/a>.<\/p>\n\n\n\n<p>backtics are deprecated and&nbsp;<code>$()<\/code>&nbsp;is POSIX compatible<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/stackoverflow.com\/a\/22709390 he&nbsp;&#8220;&nbsp;is called Command Substitution and is equivalent to&nbsp;$()&nbsp;(parenthesis), while you are using&nbsp;${}&nbsp;(curly braces). So these are equal and mean &#8220;interpret the command placed inside&#8221;: While&nbsp;${}&nbsp;expressions are used for variable substitution. From&nbsp;man bash: Command substitution&nbsp;allows the output of a command to replace the command name. There are two forms: Also,&nbsp;&#8220;&nbsp;are more difficult to handle, you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3650","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=3650"}],"version-history":[{"count":3,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3650\/revisions"}],"predecessor-version":[{"id":3723,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3650\/revisions\/3723"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=3650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=3650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=3650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}