Echo ps while preserving newlines? Echo ps while preserving newlines? bash bash

Echo ps while preserving newlines?


Same way as always: use quotes.

echo "$(ps ax)"


Simply use double-quotes in the variable that is being echo'd

echo "$(ps ax)"

this will do it without all that extra junk coding or hassle.

edit: ugh... someone beat me to it! lol


That's because echo isn't piping at all--it's interpreting the output of ps ax as a variable, and (unquoted) variables in bash essentially compress whitespace--including newlines.

If you want to pipe the output of ps, then pipe it:

ps ax | ... (some other program)