1

This will print 4 lines:

ssh root@remote_ip "service iptables restart" 

Output:

iptables: Flushing firewall rules: [ OK ] iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Unloading modules: [ OK ] iptables: Applying firewall rules: [ OK ] 

Same command inside of VAR=$()

VAR=$(ssh root@remote_ip "service iptables restart") echo $VAR 

This time it prints only this line:

iptables: Applying firewall rules: [ OK ]: filter [ OK ] 

That line is not even a line from the standard 4 line output.

makes no sense to me.

Also.. I want to see the 4 line output like the original.

0

    1 Answer 1

    2

    If the output from the command contains carriage-returns (CRLF or \r\n, as DOS does it), this will be the effect:

    $ text=$( printf 'A\r\nB\r\nC\r\n' ) $ echo $text C 

    However, if you properly quote your variable when you echo it:

    $ echo "$text" A B C 

      You must log in to answer this question.