The example below shows command rediects to a variable, especially when the output spans multiple lines

Note: $() – Strips trailing newlines.

echo “$(ps ax)”

Results

1. http://stackoverflow.com/questions/8837129/shell-scripting-store-command-output-in-variable-and-preserve-formatting
2. http://stackoverflow.com/questions/613572/capturing-multiple-line-output-to-a-bash-variable

About Gugulethu Ncube

IT enthusiast getting things done.