Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a bash script, and on a condition I'd like to output ps aux --sort -rss

However, when I write :

echo `ps aux --sort -rss`

everything is on one huge line. How do I run it so it outputs like it normally does in a terminal?

share|improve this question
Is there a reason you're not just running ps aux --sort -rss? – Michael Mrozek Nov 18 '11 at 19:09
@MichaelMrozek: I was using it in a script for a cron job. After you made your comment i probably could just call ps in the bash script and it would work as expected? I just edited my script and confirmed that it worked. +1 for your comment. I guess i'll use the accepted answer when i want to build and string and output it as one line – acidzombie24 Nov 18 '11 at 20:29
If it does work fine without echo, somebody did submit that as an answer – Michael Mrozek Nov 18 '11 at 20:32
@MichaelMrozek yes but that doesnt answer my question. In this case i should be doing it that way but it still doesnt answer the question (if i accepted it, the title of the question would be misleading. But leave it please) – acidzombie24 Nov 18 '11 at 20:38
up vote 8 down vote accepted

Quote the command:

echo "`ps aux --sort -rss`"

Otherwise bash just parses the tokens, ignoring whitespace including newlines like it does when you type it by hand.

share|improve this answer
You're invoking a sub shell to issue a command that doesn't require a sub shell. – Paul Tomblin Nov 18 '11 at 19:48
@PaulTomblin I'm answering the question that was asked, how to get it to echo with the newlines. I don't know why he wants to do it this way, but it doesn't matter for correctly answering the question. – Kevin Nov 18 '11 at 20:01
@PaulTomblin if you -1 him can you please undo it – acidzombie24 Nov 18 '11 at 20:22
Why should I undo it? It's the wrong way to get a ps result in the output of a bash script. Just because you accepted the answer doesn't make it right. – Paul Tomblin Nov 18 '11 at 20:27
Sometimes the right answer is "DON'T DO IT THE WAY YOU'RE ASKING HOW TO DO IT". Sometimes the people answering you know better than you do - that's why they're answering and you're asking. – Paul Tomblin Nov 18 '11 at 21:22

Get rid of the echo entirely, and just issue the command

ps aux --sort -rss
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.