Newline In Email Using Paste Command [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • When to wrap quotes around a shell variable?

    5 answers




I am using paste command in the mail that I am sending using shell script.
The output on the console looks perfect but the output in the mail is not in the same format. How do I make the format in the mail too same as in the console. The example below is just an example. The arrays values are dynamic. So I cannot use html table.



#!/bin/bash

BASETABLE[0]="ABC"
BASETABLE[1]="XYZ"
WORKFLOW[0]="123"
WORKFLOW[1]="789"

paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")

echo "Test" `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")` | mail -s "Test" user@xyz.com


Outout on Console:



ABC          123

XYZ 789


Output in Mail:



ABC 123 XYZ 789









share|improve this question













marked as duplicate by tripleee shell
Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 at 6:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    up vote
    0
    down vote

    favorite













    This question already has an answer here:




    • When to wrap quotes around a shell variable?

      5 answers




    I am using paste command in the mail that I am sending using shell script.
    The output on the console looks perfect but the output in the mail is not in the same format. How do I make the format in the mail too same as in the console. The example below is just an example. The arrays values are dynamic. So I cannot use html table.



    #!/bin/bash

    BASETABLE[0]="ABC"
    BASETABLE[1]="XYZ"
    WORKFLOW[0]="123"
    WORKFLOW[1]="789"

    paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")

    echo "Test" `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")` | mail -s "Test" user@xyz.com


    Outout on Console:



    ABC          123

    XYZ 789


    Output in Mail:



    ABC 123 XYZ 789









    share|improve this question













    marked as duplicate by tripleee shell
    Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 22 at 6:58


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite












      This question already has an answer here:




      • When to wrap quotes around a shell variable?

        5 answers




      I am using paste command in the mail that I am sending using shell script.
      The output on the console looks perfect but the output in the mail is not in the same format. How do I make the format in the mail too same as in the console. The example below is just an example. The arrays values are dynamic. So I cannot use html table.



      #!/bin/bash

      BASETABLE[0]="ABC"
      BASETABLE[1]="XYZ"
      WORKFLOW[0]="123"
      WORKFLOW[1]="789"

      paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")

      echo "Test" `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")` | mail -s "Test" user@xyz.com


      Outout on Console:



      ABC          123

      XYZ 789


      Output in Mail:



      ABC 123 XYZ 789









      share|improve this question














      This question already has an answer here:




      • When to wrap quotes around a shell variable?

        5 answers




      I am using paste command in the mail that I am sending using shell script.
      The output on the console looks perfect but the output in the mail is not in the same format. How do I make the format in the mail too same as in the console. The example below is just an example. The arrays values are dynamic. So I cannot use html table.



      #!/bin/bash

      BASETABLE[0]="ABC"
      BASETABLE[1]="XYZ"
      WORKFLOW[0]="123"
      WORKFLOW[1]="789"

      paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")

      echo "Test" `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")` | mail -s "Test" user@xyz.com


      Outout on Console:



      ABC          123

      XYZ 789


      Output in Mail:



      ABC 123 XYZ 789




      This question already has an answer here:




      • When to wrap quotes around a shell variable?

        5 answers








      arrays shell email paste






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 at 4:20









      user3198755

      8912




      8912




      marked as duplicate by tripleee shell
      Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 22 at 6:58


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by tripleee shell
      Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 22 at 6:58


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          The problem is your use of the echo statement. echo will not preserve newlines in an unquoted string. For example, if I have a variable containing a newline:



          my_variable="This is
          a test"


          If I echo it without quotes, newlines will be transformed into spaces:



          $ echo $my_variable
          This is a test


          But if I quote the variable, newlines will be preserved:



          $ echo "$my_variable"
          This is
          a test


          So you can get the output you want by simply moving the closing quote in your echo statement, so that it becomes:



          echo "Test `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")`"


          This will output:



          Test
          ABC 123

          XYZ 789


          Instead of:



          Test ABC 123 XYZ 789





          share|improve this answer




























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            The problem is your use of the echo statement. echo will not preserve newlines in an unquoted string. For example, if I have a variable containing a newline:



            my_variable="This is
            a test"


            If I echo it without quotes, newlines will be transformed into spaces:



            $ echo $my_variable
            This is a test


            But if I quote the variable, newlines will be preserved:



            $ echo "$my_variable"
            This is
            a test


            So you can get the output you want by simply moving the closing quote in your echo statement, so that it becomes:



            echo "Test `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")`"


            This will output:



            Test
            ABC 123

            XYZ 789


            Instead of:



            Test ABC 123 XYZ 789





            share|improve this answer

























              up vote
              0
              down vote



              accepted










              The problem is your use of the echo statement. echo will not preserve newlines in an unquoted string. For example, if I have a variable containing a newline:



              my_variable="This is
              a test"


              If I echo it without quotes, newlines will be transformed into spaces:



              $ echo $my_variable
              This is a test


              But if I quote the variable, newlines will be preserved:



              $ echo "$my_variable"
              This is
              a test


              So you can get the output you want by simply moving the closing quote in your echo statement, so that it becomes:



              echo "Test `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")`"


              This will output:



              Test
              ABC 123

              XYZ 789


              Instead of:



              Test ABC 123 XYZ 789





              share|improve this answer























                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                The problem is your use of the echo statement. echo will not preserve newlines in an unquoted string. For example, if I have a variable containing a newline:



                my_variable="This is
                a test"


                If I echo it without quotes, newlines will be transformed into spaces:



                $ echo $my_variable
                This is a test


                But if I quote the variable, newlines will be preserved:



                $ echo "$my_variable"
                This is
                a test


                So you can get the output you want by simply moving the closing quote in your echo statement, so that it becomes:



                echo "Test `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")`"


                This will output:



                Test
                ABC 123

                XYZ 789


                Instead of:



                Test ABC 123 XYZ 789





                share|improve this answer












                The problem is your use of the echo statement. echo will not preserve newlines in an unquoted string. For example, if I have a variable containing a newline:



                my_variable="This is
                a test"


                If I echo it without quotes, newlines will be transformed into spaces:



                $ echo $my_variable
                This is a test


                But if I quote the variable, newlines will be preserved:



                $ echo "$my_variable"
                This is
                a test


                So you can get the output you want by simply moving the closing quote in your echo statement, so that it becomes:



                echo "Test `paste -d' ' <(printf "n") <(printf "n%-12.12sn" "${BASETABLE[@]}") <(printf "n%sn" "${WORKFLOW[@]}")`"


                This will output:



                Test
                ABC 123

                XYZ 789


                Instead of:



                Test ABC 123 XYZ 789






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 at 4:29









                larsks

                112k18184194




                112k18184194















                    Popular posts from this blog

                    Contact image not getting when fetch all contact list from iPhone by CNContact

                    count number of partitions of a set with n elements into k subsets

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks