echo and carriage returns? <sec>

echo and carriage returns? <sec>

Post by s.. » Tue, 20 Mar 2001 05:48:17



Why doesn't this:

        PS_OUTPUT=`ps  -ef`
        echo  ${PS_OUTPUT}

produce the same output as this:

        ps  -ef

ie.  The same number of lines.

TIA!

 
 
 

echo and carriage returns? <sec>

Post by Anthony Borl » Tue, 20 Mar 2001 07:50:30



Quote:> Why doesn't this:

> PS_OUTPUT=`ps  -ef`
> echo  ${PS_OUTPUT}

> produce the same output as this:

> ps  -ef

> ie.  The same number of lines.

The normal behaviour of the backtick (`...`) expansion is to delete trailing
newlines. So, rather than getting:

     line 1
     line 2
     ...
     ...

assigned to your shell variable, you get:

    line1 line2 ... ...

I hope this helps, in terms of explaining the observed behaviour.

 
 
 

echo and carriage returns? <sec>

Post by Peter Sundstro » Tue, 20 Mar 2001 07:37:59



Quote:> Why doesn't this:

> PS_OUTPUT=`ps  -ef`
> echo  ${PS_OUTPUT}

> produce the same output as this:

> ps  -ef

> ie.  The same number of lines.

Make it

echo "$PS_OUTPUT"