<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: MSugitani</title>
    <description>The latest articles on DEV Community by MSugitani (@m_sgi).</description>
    <link>https://dev.to/m_sgi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F995698%2F5ef9c213-260a-48c8-829f-85198ef9f82b.png</url>
      <title>DEV Community: MSugitani</title>
      <link>https://dev.to/m_sgi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/m_sgi"/>
    <language>en</language>
    <item>
      <title>How to make newline for bash output on CGI/bash</title>
      <dc:creator>MSugitani</dc:creator>
      <pubDate>Sat, 24 Dec 2022 13:29:24 +0000</pubDate>
      <link>https://dev.to/m_sgi/how-to-make-newline-for-bash-output-on-cgibash-3opm</link>
      <guid>https://dev.to/m_sgi/how-to-make-newline-for-bash-output-on-cgibash-3opm</guid>
      <description>&lt;h2&gt;
  
  
  Use CGI for dynamic web site
&lt;/h2&gt;

&lt;p&gt;In case of Web site that using CGI not static html we can show contents dynamically.&lt;br&gt;
Like showing result of Linux command.&lt;br&gt;
Put this sample to /var/www/cgi-bin/ as test.cgi&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;!/bin/bash
echo “Content-type: text/html”
echo “”
echo “Hello World!”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is same as static html.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft4zistckutb8e5wqrsa5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft4zistckutb8e5wqrsa5.png" alt="Image description" width="454" height="108"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
echo “Content-type: text/html”
echo “”
echo “Hello World!”
echo “&amp;lt;br&amp;gt;”
date
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If use date command it can showing date dynamically.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv3mbks1ej89jeygj49ns.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv3mbks1ej89jeygj49ns.png" alt="Image description" width="800" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  If the command produces multiple lines of output when executed
&lt;/h2&gt;

&lt;p&gt;if use command ifconfig eth0&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5sggyy6urfi42m9otdar.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5sggyy6urfi42m9otdar.png" alt="Image description" width="800" height="232"&gt;&lt;/a&gt;&lt;br&gt;
There are no newline.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to resolve?
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
echo “Content-type: text/html”
echo “”

echo “Hello World!”
echo “&amp;lt;br&amp;gt;”
date
echo “&amp;lt;br&amp;gt;”
echo “&amp;lt;br&amp;gt;”

sudo /usr/sbin/ifconfig eth0 &amp;gt; /var/www/html/ifcofigeth0

while read line
do
echo $line
echo “&amp;lt;br&amp;gt;”
done &amp;lt; /var/www/html/ifcofigeth0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output to file once and read the file 1 line by 1 line using while.&lt;br&gt;
Using echo for output and use br for make newline.&lt;br&gt;
Repeat this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdkgbp6uuvs8eyripp2zw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdkgbp6uuvs8eyripp2zw.png" alt="Image description" width="800" height="379"&gt;&lt;/a&gt;&lt;br&gt;
It is showing with newline.&lt;/p&gt;

&lt;p&gt;In case of using echo command I found article on this.&lt;br&gt;
it will use \n for make newline.&lt;/p&gt;

&lt;p&gt;But It seem there are no article in case of If the command produces multiple lines of output when executed.&lt;/p&gt;

&lt;p&gt;If you have any other good ideas please let me know.&lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
  </channel>
</rss>
