0

If I grep our syslogs for a specific term, I get a nice output of those logs matching my term and each entry on a separate line.

If I save that to a variable so I can use it in a script as such:

results=$( grep "term" logs )
echo $results

then all the logs run together and are not human readable.

How can I make it look cleaner so when I do echo $results, I can actually read the output?

Thanks,

Barmar
  • 741,623
  • 53
  • 500
  • 612
Moneer81
  • 295
  • 2
  • 11

1 Answers1

2

Quote it:

echo "$results"

This preserves all the whitespace, instead of using it for word splitting.

In general, you should almost always quote variables, unless you have a specific reason not to.

Barmar
  • 741,623
  • 53
  • 500
  • 612