=========================
bash-command-substitution
=========================

.. raw:: html

   <table class="provenance-header" style="border: 0; border-collapse: collapse; margin: 0 0 16px 0; width: 100%;">

.. raw:: html

   <tr style="border: 0;">

.. raw:: html

   <td style="border: 0; vertical-align: top; padding: 0 24px 0 0;">

..

   | **Source:**
     https://foxhop.net/f3f1d8ba-2f95-11f1-8421-e86a64d24d78/bash-command-substitution
   | **Snapshot:** 2026-10-16T05:30:12Z
   | **Generator:** Remarkbox ``d747782``

   *This is a thread snapshot. The living document lives at the source
   URI above — it may have been edited, extended, or replied-to since.*

.. raw:: html

   </td>

.. raw:: html

   <td style="border: 0; vertical-align: top; width: 200px; text-align: right;">

.. figure:: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKQAAACkAQAAAAAxzrjsAAABcUlEQVR42tVXMY4DQQxC9wH+/0t+4DN4I6VIcxJFboqNZgvWg4FxMB+W8MVvAdBPihLprX7waf3lLYYzxt0vLO7Q2w4uSAWa3mXbwl2oPT5TdBPXxxeWAhTrNaHLL41b5NcCeFs1PXgt2mpsVmmM+jr8CgYMESZXnXrXC3K92zht42yVTr022SEeCz0eZI3Rn7Cl2cE1lm0BpX0WcEkPSvzoeaCk3xAcra0cBrFeBdcy25qfAEpeVvw2LwsjH1Ctb1tseKYVvC4p5Y7TjOnezOmjw68pdgA7JXHOq/B7kR6JbTgsvSUedJEuRcFmo9O3uYt4f5WIn5Z+QzETZbjWdfp280OGB2ujhTtzzZJjuOc355l8xSlCRi3XwXnaluBp3UMZcXLfG/qOULuPM585KsJFcX7Y41vHkxmiNu9kdAgV9L43TyrMJoNRxLU7lCTLNNHDVW4N5w5b91sGyFyYMbNauNFDKrUnPET05sn/8z/rF+Ys2UBZ8+JEAAAAAElFTkSuQmCC
   :alt: Scan for living source

   Scan for living source

.. raw:: html

   </td>

.. raw:: html

   </tr>

.. raw:: html

   </table>

Bash Command Substitution
=========================

There are two ways:

-  wrap the command in "\`":

..

   .. container::
      :name: cb1

      ::

         myvar=`cat /etc/motd`

-  wrap the command in "$()":

..

   .. container::
      :name: cb2

      ::

         myvar=$(cat /etc/motd)

Choose either then then try this:

   .. container::
      :name: cb3

      ::

         echo $myvar

--------------

| **Source:**
  https://foxhop.net/f3f1d8ba-2f95-11f1-8421-e86a64d24d78/bash-command-substitution
| **Snapshot:** 2026-10-16T05:30:12Z
| **Generator:** Remarkbox ``d747782``
