Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Upon executing a command as <code>$(command)</code> allows the <a href="http://www.gnu.org/software/bash/manual/bashref.html#Command-Substitution">output of the command to replace itself</a>.</p> <p>When you say:</p> <pre><code>a=$(false) # false fails; the output of false is stored in the variable a </code></pre> <p>the output produced by the command <code>false</code> is stored in the variable <code>a</code>. Moreover, the exit code is the same as produced by the command. <code>help false</code> would tell:</p> <pre><code>false: false Return an unsuccessful result. Exit Status: Always fails. </code></pre> <p>On the other hand, saying:</p> <pre><code>$ false # Exit code: 1 $ a="" # Exit code: 0 $ echo $? # Prints 0 </code></pre> <p>causes the exit code for the assignment to <code>a</code> to be returned which is <code>0</code>.</p> <hr> <p>EDIT: </p> <p>Quoting from the <a href="http://www.gnu.org/software/bash/manual/bashref.html#Simple-Command-Expansion">manual</a>:</p> <blockquote> <p>If one of the expansions contained a command substitution, the exit status of the command is the exit status of the last command substitution performed.</p> </blockquote> <p>Quoting from <a href="http://mywiki.wooledge.org/BashFAQ/002">BASHFAQ/002</a>:</p> <blockquote> <p><strong>How can I store the return value and/or output of a command in a variable?</strong></p> <p>...</p> <p><code>output=$(command)</code></p> <p><code>status=$?</code></p> <p>The assignment to <code>output</code> has no effect on <code>command</code>'s exit status, which is still in <code>$?</code>.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload