Need complete output into variable in bash [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0
















This question already has an answer here:



  • How can I preserve new lines coming from a command's output during variable assignment?

    1 answer



  • Why does my shell script choke on whitespace or other special characters?

    4 answers



  • Why is printf better than echo?

    4 answers



Following is the command which is in shell script.



var="$(sshpass -p 'password' ssh -o "StrictHostKeyChecking=no" username@hostip <<-EOF
command to run on remote host
EOF
)"


when i echo $var, output is displayed without spaces and new line i.e, trimming spaces and new lines.
i need complete output from the remote host with spaces and new line.



On Running Manually through CLI, getting correct output i.e, with spaces and line. But on echoing the varibale($var) output getting trimmed.



tried this echo $var, still no luck, getting output trimmed of white spaces and new line.










share|improve this question















marked as duplicate by steeldriver, Rui F Ribeiro, roaima, Romeo Ninov, Kusalananda bash
Users with the  bash badge can single-handedly close bash 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();

);
);
);
Jan 29 at 19:20


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.






















    0
















    This question already has an answer here:



    • How can I preserve new lines coming from a command's output during variable assignment?

      1 answer



    • Why does my shell script choke on whitespace or other special characters?

      4 answers



    • Why is printf better than echo?

      4 answers



    Following is the command which is in shell script.



    var="$(sshpass -p 'password' ssh -o "StrictHostKeyChecking=no" username@hostip <<-EOF
    command to run on remote host
    EOF
    )"


    when i echo $var, output is displayed without spaces and new line i.e, trimming spaces and new lines.
    i need complete output from the remote host with spaces and new line.



    On Running Manually through CLI, getting correct output i.e, with spaces and line. But on echoing the varibale($var) output getting trimmed.



    tried this echo $var, still no luck, getting output trimmed of white spaces and new line.










    share|improve this question















    marked as duplicate by steeldriver, Rui F Ribeiro, roaima, Romeo Ninov, Kusalananda bash
    Users with the  bash badge can single-handedly close bash 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();

    );
    );
    );
    Jan 29 at 19:20


    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.




















      0












      0








      0









      This question already has an answer here:



      • How can I preserve new lines coming from a command's output during variable assignment?

        1 answer



      • Why does my shell script choke on whitespace or other special characters?

        4 answers



      • Why is printf better than echo?

        4 answers



      Following is the command which is in shell script.



      var="$(sshpass -p 'password' ssh -o "StrictHostKeyChecking=no" username@hostip <<-EOF
      command to run on remote host
      EOF
      )"


      when i echo $var, output is displayed without spaces and new line i.e, trimming spaces and new lines.
      i need complete output from the remote host with spaces and new line.



      On Running Manually through CLI, getting correct output i.e, with spaces and line. But on echoing the varibale($var) output getting trimmed.



      tried this echo $var, still no luck, getting output trimmed of white spaces and new line.










      share|improve this question

















      This question already has an answer here:



      • How can I preserve new lines coming from a command's output during variable assignment?

        1 answer



      • Why does my shell script choke on whitespace or other special characters?

        4 answers



      • Why is printf better than echo?

        4 answers



      Following is the command which is in shell script.



      var="$(sshpass -p 'password' ssh -o "StrictHostKeyChecking=no" username@hostip <<-EOF
      command to run on remote host
      EOF
      )"


      when i echo $var, output is displayed without spaces and new line i.e, trimming spaces and new lines.
      i need complete output from the remote host with spaces and new line.



      On Running Manually through CLI, getting correct output i.e, with spaces and line. But on echoing the varibale($var) output getting trimmed.



      tried this echo $var, still no luck, getting output trimmed of white spaces and new line.





      This question already has an answer here:



      • How can I preserve new lines coming from a command's output during variable assignment?

        1 answer



      • Why does my shell script choke on whitespace or other special characters?

        4 answers



      • Why is printf better than echo?

        4 answers







      bash shell ssh echo sshpass






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 29 at 19:03









      msp9011

      4,36944066




      4,36944066










      asked Jan 29 at 18:43









      sachin_ghagaresachin_ghagare

      32




      32




      marked as duplicate by steeldriver, Rui F Ribeiro, roaima, Romeo Ninov, Kusalananda bash
      Users with the  bash badge can single-handedly close bash 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();

      );
      );
      );
      Jan 29 at 19:20


      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 steeldriver, Rui F Ribeiro, roaima, Romeo Ninov, Kusalananda bash
      Users with the  bash badge can single-handedly close bash 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();

      );
      );
      );
      Jan 29 at 19:20


      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.






















          0






          active

          oldest

          votes

















          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes

          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)