title: Retain color and format of Bash command in a variable
body: <p>team!<br>
  I want to execute bash command into variable.</p>
  <pre class="lang-bash prettyprint-override"><code>COMMAND=&quot;systemctl status wazuh-manager --no-pager&quot;
  NEWMESSAGE=&quot;$($COMMAND)&quot;
  if [[ -n $NLINES ]]; then
       $NEWMESSAGE | tail -n $NLINES
  fi
  if [[ -n $OUTPUTFILE ]]; then
      echo -e $NEWMESSAGE |&amp; tee -a $OUTPUTFILE
  fi
  </code></pre>
  <p>I have output like this. <br>
  Single line with no color text.</p>
  <pre><code>● wazuh-manager.service - Wazuh manager Loaded: loaded (/lib/systemd/system/wazuh-manager.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2022-05-30 19:58:47 MSK; 17h ago Process: 12449 ExecStart=/usr/bin/env /var/ossec/bin/wazuh-control start (code=exited, status=0/SUCCESS) Tasks: 138 (limit: 28719) Memory: 1.0G CGroup: /system.slice/wazuh-manager.service ├─12505 /var/ossec/framework/python/bin/python3 /var/ossec/api/scripts/wazuh-apid.py ├─12526 /var/ossec/bin/wazuh-integratord ├─12547 /var/ossec/bin/wazuh-authd ├─12563 /var/ossec/bin/wazuh-db ├─12577 /var/ossec/framework/python/bin/python3 /var/ossec/api/scripts/wazuh-apid.py ├─12580 /var/ossec/framework/python/bin/python3 /var/ossec/api/scripts/wazuh-apid.py ├─12592 /var/ossec/bin/wazuh-execd ├─12606 /var/ossec/bin/wazuh-analysisd ├─12621 /var/ossec/bin/wazuh-syscheckd ├─12683 /var/ossec/bin/wazuh-remoted ├─12715 /var/ossec/bin/wazuh-logcollector ├─12735 /var/ossec/bin/wazuh-monitord └─12756 /var/ossec/bin/wazuh-modulesd May 30 19:58:39 UBUNTU-2004-SRV-2.home.local env[12449]: Started wazuh-analysisd... May 30 19:58:40 UBUNTU-2004-SRV-2.home.local env[12449]: Started wazuh-syscheckd... May 30 19:58:41 UBUNTU-2004-SRV-2.home.local env[12449]: Started wazuh-remoted... May 30 19:58:43 UBUNTU-2004-SRV-2.home.local env[12449]: Started wazuh-logcollector... May 30 19:58:44 UBUNTU-2004-SRV-2.home.local env[12449]: Started wazuh-monitord... May 30 19:58:44 UBUNTU-2004-SRV-2.home.local env[12753]: 2022/05/30 19:58:44 wazuh-modulesd: WARNING: The &lt;ignore_time&gt; tag at module 'vulnerability-detector' is deprecated for version newer than 4.3. May 30 19:58:44 UBUNTU-2004-SRV-2.home.local env[12753]: 2022/05/30 19:58:44 wazuh-modulesd: WARNING: Invalid option 'os' for 'msu' provider at 'vulnerability-detector' May 30 19:58:45 UBUNTU-2004-SRV-2.home.local env[12449]: Started wazuh-modulesd... May 30 19:58:47 UBUNTU-2004-SRV-2.home.local env[12449]: Completed. May 30 19:58:47 UBUNTU-2004-SRV-2.home.local systemd[1]: Started Wazuh manager.
  </code></pre>
  <p>but if i run command in console i have different format.</p>
  <pre class="lang-bash prettyprint-override"><code>systemctl status wazuh-manager --no-pager
  ● wazuh-manager.service - Wazuh manager
       Loaded: loaded (/lib/systemd/system/wazuh-manager.service; enabled; vendor preset: enabled)
       Active: active (running) since Mon 2022-05-30 19:58:47 MSK; 18h ago
      Process: 12449 ExecStart=/usr/bin/env /var/ossec/bin/wazuh-control start (code=exited, status=0/SUCCESS)
        Tasks: 138 (limit: 28719)
       Memory: 1.0G
       CGroup: /system.slice/wazuh-manager.service
               ├─12505 /var/ossec/framework/python/bin/python3 /var/ossec/api/scripts/wazuh-apid.py
               ├─12526 /var/ossec/bin/wazuh-integratord
               ├─12547 /var/ossec/bin/wazuh-authd
               ├─12563 /var/ossec/bin/wazuh-db
               ├─12577 /var/ossec/framework/python/bin/python3 /var/ossec/api/scripts/wazuh-apid.py
               ├─12580 /var/ossec/framework/python/bin/python3 /var/ossec/api/scripts/wazuh-apid.py
               ├─12592 /var/ossec/bin/wazuh-execd
               ├─12606 /var/ossec/bin/wazuh-analysisd
               ├─12621 /var/ossec/bin/wazuh-syscheckd
               ├─12683 /var/ossec/bin/wazuh-remoted
               ├─12715 /var/ossec/bin/wazuh-logcollector
               ├─12735 /var/ossec/bin/wazuh-monitord
               └─12756 /var/ossec/bin/wazuh-modulesd
  
  May 30 19:58:39 UBUNTU-2004-SRV-2.home.local env[12449]: Started wazuh-analysisd...
  May 30 19:58:40 UBUNTU-2004-SRV-2.home.local env[12449]: Started wazuh-syscheckd...
  May 30 19:58:41 UBUNTU-2004-SRV-2.home.local env[12449]: Started wazuh-remoted...
  May 30 19:58:43 UBUNTU-2004-SRV-2.home.local env[12449]: Started wazuh-logcollector...
  May 30 19:58:44 UBUNTU-2004-SRV-2.home.local env[12449]: Started wazuh-monitord...
  May 30 19:58:44 UBUNTU-2004-SRV-2.home.local env[12753]: 2022/05/30 19:58:44 wazuh-modulesd: WARNING: The &lt;ignore…n 4.3.
  May 30 19:58:44 UBUNTU-2004-SRV-2.home.local env[12753]: 2022/05/30 19:58:44 wazuh-modulesd: WARNING: Invalid opt…ector'
  May 30 19:58:45 UBUNTU-2004-SRV-2.home.local env[12449]: Started wazuh-modulesd...
  May 30 19:58:47 UBUNTU-2004-SRV-2.home.local env[12449]: Completed.
  May 30 19:58:47 UBUNTU-2004-SRV-2.home.local systemd[1]: Started Wazuh manager.
  Hint: Some lines were ellipsized, use -l to show in full.
  </code></pre>
  <blockquote>
  <p><strong>How to save text format?</strong></p>
  </blockquote>